mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
Merge pull request #65 from LeoXV1/Leo_add_claude
Add Anthropic Claude Api
This commit is contained in:
commit
b72b6adbac
5 changed files with 44 additions and 3 deletions
|
|
@ -10,6 +10,9 @@ OPENAI_API_MODEL: "gpt-4"
|
|||
MAX_TOKENS: 1500
|
||||
RPM: 10
|
||||
|
||||
#### if Anthropic
|
||||
#Anthropic_API_KEY: "YOUR_API_KEY"
|
||||
|
||||
#### if AZURE, check https://github.com/openai/openai-cookbook/blob/main/examples/azure/chat.ipynb
|
||||
|
||||
#OPENAI_API_TYPE: "azure"
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ import asyncio
|
|||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.llm import LLM
|
||||
|
||||
from metagpt.llm import Claude
|
||||
|
||||
async def main():
|
||||
llm = LLM()
|
||||
|
||||
claude = Claude()
|
||||
logger.info(await claude.aask('你好,请进行自我介绍'))
|
||||
logger.info(await llm.aask('hello world'))
|
||||
logger.info(await llm.aask_batch(['hi', 'write python hello world.']))
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ class Config(metaclass=Singleton):
|
|||
self.max_tokens_rsp = self._get('MAX_TOKENS', 2048)
|
||||
self.deployment_id = self._get('DEPLOYMENT_ID')
|
||||
|
||||
self.claude_api_key = self._get('Anthropic_API_KEY')
|
||||
|
||||
self.serpapi_api_key = self._get('SERPAPI_API_KEY')
|
||||
self.serper_api_key = self._get('SERPER_API_KEY')
|
||||
self.google_api_key = self._get('GOOGLE_API_KEY')
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@
|
|||
"""
|
||||
|
||||
from metagpt.provider.openai_api import OpenAIGPTAPI as LLM
|
||||
from metagpt.provider.anthropic_api import Claude2 as Claude
|
||||
|
||||
DEFAULT_LLM = LLM()
|
||||
|
||||
CLAUDE_LLM = Claude()
|
||||
|
||||
async def ai_func(prompt):
|
||||
"""使用LLM进行QA"""
|
||||
|
|
|
|||
34
metagpt/provider/anthropic_api.py
Normal file
34
metagpt/provider/anthropic_api.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2023/7/21 11:15
|
||||
@Author : Leo Xiao
|
||||
@File : anthropic_api.py
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import anthropic
|
||||
from anthropic import Anthropic
|
||||
from metagpt.config import CONFIG
|
||||
|
||||
class Claude2:
|
||||
def ask(self, prompt):
|
||||
client = Anthropic(api_key=CONFIG.claude_api_key)
|
||||
|
||||
res = client.completions.create(
|
||||
model="claude-2",
|
||||
prompt=f"{anthropic.HUMAN_PROMPT} {prompt} {anthropic.AI_PROMPT}",
|
||||
max_tokens_to_sample=1000,
|
||||
)
|
||||
return res.completion
|
||||
|
||||
async def aask(self, prompt):
|
||||
client = Anthropic(api_key=CONFIG.claude_api_key)
|
||||
|
||||
res = client.completions.create(
|
||||
model="claude-2",
|
||||
prompt=f"{anthropic.HUMAN_PROMPT} {prompt} {anthropic.AI_PROMPT}",
|
||||
max_tokens_to_sample=1000,
|
||||
)
|
||||
return res.completion
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue