-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
69 additions
and
30 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,2 @@ | ||
from .http import client | ||
from .messages import SafeMessage, ensure_safe |
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,3 @@ | ||
from httpx import AsyncClient | ||
|
||
client = AsyncClient(http2=True) |
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
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 @@ | ||
from promplate import Message | ||
from promplate.llm.openai import AsyncChatComplete, AsyncChatGenerate, AsyncChatOpenAI | ||
from promplate_trace.auto import patch | ||
|
||
from ..config import env | ||
from .common import client | ||
from .dispatch import link_llm | ||
|
||
complete = AsyncChatComplete(http_client=client, base_url=env.siliconflow_base_url, api_key=env.siliconflow_api_key) | ||
generate = AsyncChatGenerate(http_client=client, base_url=env.siliconflow_base_url, api_key=env.siliconflow_api_key) | ||
|
||
|
||
@link_llm("Qwen/") | ||
@link_llm("01-ai/") | ||
@link_llm("THUDM/") | ||
@link_llm("deepseek-ai/") | ||
class Siliconflow(AsyncChatOpenAI): | ||
async def complete(self, prompt: str | list[Message], /, **config): | ||
config = self._run_config | config | ||
return (await complete(prompt, **config)).removeprefix(" ") | ||
|
||
async def generate(self, prompt: str | list[Message], /, **config): | ||
config = self._run_config | config | ||
|
||
async for token in generate(prompt, **config): | ||
yield token | ||
|
||
def bind(self, **run_config): # type: ignore | ||
self._run_config.update(run_config) # inplace | ||
return self | ||
|
||
|
||
siliconflow = Siliconflow() | ||
|
||
|
||
siliconflow.complete = patch.chat.acomplete(siliconflow.complete) # type: ignore | ||
siliconflow.generate = patch.chat.agenerate(siliconflow.generate) # type: ignore |