-
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.
Showing
6 changed files
with
50 additions
and
4 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
from .octoai import octoai | ||
from .openai import openai | ||
from .qwen import qwen | ||
from .groq import groq |
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,44 @@ | ||
from promplate import Message | ||
from promplate.llm.base import AsyncComplete, AsyncGenerate | ||
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 | ||
|
||
GROQ_BASE_URL = "https://api.groq.com/openai/v1" | ||
|
||
complete: AsyncComplete = AsyncChatComplete(http_client=client, base_url=GROQ_BASE_URL, api_key=env.groq_api_key) | ||
generate: AsyncGenerate = AsyncChatGenerate(http_client=client, base_url=GROQ_BASE_URL, api_key=env.groq_api_key) | ||
|
||
|
||
@link_llm("gemma") | ||
@link_llm("mixtral") | ||
class Groq(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 | ||
|
||
first_token = True | ||
|
||
async for token in generate(prompt, **config): | ||
if token and first_token: | ||
first_token = False | ||
yield token.removeprefix(" ") | ||
else: | ||
yield token | ||
|
||
def bind(self, **run_config): # type: ignore | ||
self._run_config.update(run_config) # inplace | ||
return self | ||
|
||
|
||
groq = Groq().bind(model="mixtral-8x7b-32768") | ||
|
||
|
||
groq.complete = patch.chat.acomplete(groq.complete) # type: ignore | ||
groq.generate = patch.chat.agenerate(groq.generate) # type: ignore |
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