Update Anthropic API (#2482)

update anthropic API

Change API URL

Parse new result correctly

Fix lint

Fix lint
pull/2483/head
jkub6 1 year ago committed by GitHub
parent 14ba7ac86a
commit 2922ba9b24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -360,18 +360,22 @@ def query(prompt, model="text-davinci-003", max_tokens=100, temperature=0.0):
def query_anthropic(prompt, model="claude-v1", max_tokens=100, temperature=0.0):
data = {
"prompt": prompt,
"messages": [{"role": "user", "content": prompt}],
"model": model,
"temperature": temperature,
"max_tokens_to_sample": max_tokens,
"max_tokens": max_tokens,
"stop_sequences": ["\n\nHuman:"],
}
headers = {"x-api-key": config.ai_anthropic_api_key.value, "Content-Type": "application/json"}
url = "https://api.anthropic.com/v1/complete"
headers = {
"x-api-key": config.ai_anthropic_api_key.value,
"Content-Type": "application/json",
"anthropic-version": "2023-06-01",
}
url = "https://api.anthropic.com/v1/messages"
response = _requests().post(url, data=json.dumps(data), headers=headers)
data = response.json()
try:
return data["completion"].strip()
return data["content"][0]["text"].strip()
except KeyError:
print(M.error(f"Anthropic API error: {data}"))
return f"Anthropic API error: {data['detail']}"

Loading…
Cancel
Save