forked from reworkd/AgentGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ποΈ Make content refresher async (reworkd#1184)
* ποΈ Make content refresher async * ποΈ Make content refresher async * ποΈ Make content refresher async
- Loading branch information
Showing
3 changed files
with
94 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,4 @@ yarn-error.log* | |
.sentryclirc | ||
/volumes/ | ||
schema.prismae | ||
*.sql |
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,42 @@ | ||
from typing import Any, Optional | ||
|
||
from anthropic import AsyncAnthropic | ||
from pydantic import BaseModel | ||
|
||
|
||
class AbstractPrompt(BaseModel): | ||
def to_string(self) -> str: | ||
raise NotImplementedError | ||
|
||
|
||
class HumanAssistantPrompt(AbstractPrompt): | ||
assistant_prompt: str | ||
human_prompt: str | ||
|
||
def to_string(self) -> str: | ||
return ( | ||
f"""\n\nHuman: {self.human_prompt}\n\nAssistant: {self.assistant_prompt}""" | ||
) | ||
|
||
|
||
class ClaudeService: | ||
def __init__(self, api_key: Optional[str], model: str = "claude-2"): | ||
self.claude = AsyncAnthropic(api_key=api_key) | ||
self.model = model | ||
|
||
async def completion( | ||
self, | ||
prompt: AbstractPrompt, | ||
max_tokens_to_sample: int, | ||
temperature: int = 0, | ||
**kwargs: Any, | ||
) -> str: | ||
return ( | ||
await self.claude.completions.create( | ||
model=self.model, | ||
prompt=prompt.to_string(), | ||
max_tokens_to_sample=max_tokens_to_sample, | ||
temperature=temperature, | ||
**kwargs, | ||
) | ||
).completion.strip() |