-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat](AI) add several AI related features (#901)
- [x] user can input `=== {question}` to chat with AI - [x] find standby using AI if standby is not found - [x] add a config - [x] user can input `==> {title} - {artists_name}` in search bar to play a song - [x] user can create a playlist based on plain text
- Loading branch information
Showing
22 changed files
with
943 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import asyncio | ||
import socket | ||
|
||
from openai import AsyncOpenAI | ||
|
||
from feeluown.utils.aio import run_afn | ||
|
||
|
||
async def a_handle_stream(stream): | ||
rsock, wsock = socket.socketpair() | ||
rr, rw = await asyncio.open_connection(sock=rsock) | ||
_, ww = await asyncio.open_connection(sock=wsock) | ||
|
||
async def write_task(): | ||
async for chunk in stream: | ||
content = chunk.choices[0].delta.content or '' | ||
ww.write(content.encode('utf-8')) | ||
ww.write_eof() | ||
await ww.drain() | ||
ww.close() | ||
await ww.wait_closed() | ||
|
||
task = run_afn(write_task) | ||
return rr, rw, task | ||
|
||
|
||
class AI: | ||
def __init__(self, base_url, api_key, model): | ||
self.base_url = base_url | ||
self.api_key = api_key | ||
self.model = model | ||
|
||
def get_async_client(self): | ||
return AsyncOpenAI( | ||
base_url=self.base_url, | ||
api_key=self.api_key, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.