From fc92dd784389f5bb8ba5efa71dbab6e81c6dd051 Mon Sep 17 00:00:00 2001 From: Josh XT <102809327+Josh-XT@users.noreply.github.com> Date: Wed, 6 Mar 2024 05:46:53 -0500 Subject: [PATCH] Add Claude 3 Support (#1127) * Update Claude Provider to support Claude 3 * Update models link * Update docs --- agixt/providers/claude.py | 26 +++++++++++++++----------- docs/3-Providers/Anthropic Claude.md | 9 +++++---- requirements.txt | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/agixt/providers/claude.py b/agixt/providers/claude.py index 378689302f5a..f79f9ba44ea5 100644 --- a/agixt/providers/claude.py +++ b/agixt/providers/claude.py @@ -8,31 +8,35 @@ import anthropic -# List of models available at https://console.anthropic.com/docs/api/reference +# List of models available at https://docs.anthropic.com/claude/docs/models-overview +# Get API key at https://console.anthropic.com/settings/keys class ClaudeProvider: def __init__( self, ANTHROPIC_API_KEY: str = "", - AI_MODEL: str = "claude-2", - MAX_TOKENS: int = 100000, + AI_MODEL: str = "claude-3-opus-20240229", + MAX_TOKENS: int = 200000, AI_TEMPERATURE: float = 0.7, **kwargs, ): self.ANTHROPIC_API_KEY = ANTHROPIC_API_KEY - self.MAX_TOKENS = MAX_TOKENS if MAX_TOKENS else 100000 - self.AI_MODEL = AI_MODEL if AI_MODEL else "claude-2" + self.MAX_TOKENS = MAX_TOKENS if MAX_TOKENS else 200000 + self.AI_MODEL = AI_MODEL if AI_MODEL else "claude-3-opus-20240229" self.AI_TEMPERATURE = AI_TEMPERATURE if AI_TEMPERATURE else 0.7 async def inference(self, prompt, tokens: int = 0): - max_new_tokens = int(self.MAX_TOKENS) - int(tokens) try: c = anthropic.Client(api_key=self.ANTHROPIC_API_KEY) - return c.completion( - prompt=f"{anthropic.HUMAN_PROMPT}{prompt}{anthropic.AI_PROMPT}", - stop_sequences=[anthropic.HUMAN_PROMPT], + response = c.messages.create( + messages=[ + { + "role": "user", + "content": prompt, + } + ], model=self.AI_MODEL, - temperature=float(self.AI_TEMPERATURE), - max_tokens_to_sample=max_new_tokens, + max_tokens=4096, ) + return response.content[0].text except Exception as e: return f"Claude Error: {e}" diff --git a/docs/3-Providers/Anthropic Claude.md b/docs/3-Providers/Anthropic Claude.md index b9951fa2a2ff..1313dbc450f9 100644 --- a/docs/3-Providers/Anthropic Claude.md +++ b/docs/3-Providers/Anthropic Claude.md @@ -1,11 +1,12 @@ # Anthropic Claude + - [Anthropic Claude](https://console.anthropic.com/docs/access) - [AGiXT](https://github.com/Josh-XT/AGiXT) ## Quick Start Guide + ### Update your agent settings + 1. Set `AI_PROVIDER` to `claude`. -2. Set `ANTHROPIC_API_KEY` to your OpenAI API key. -3. Set `AI_MODEL` to `claude-v1-100k` for the 100k model, or `claude-v1` for the regular model. -4. Set `AI_TEMPERATURE` to a value between 0 and 1. The higher the value, the more creative the output. -5. Set `MAX_TOKENS` to the maximum number of tokens to generate. \ No newline at end of file +2. Set `ANTHROPIC_API_KEY` to your OpenAI API key. Get your Anthroic API key at +3. Set `AI_MODEL` to `claude-3-opus-20240229`. List of models available at . diff --git a/requirements.txt b/requirements.txt index b8797320d228..d0c5891aa535 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ agixtsdk==0.0.31 safeexecute==0.0.9 google-generativeai==0.3.2 discord==2.3.2 -anthropic==0.16.0 +anthropic==0.18.1 arxiv==1.4.8 PyGithub==2.2.0 hugchat==0.4.0