-
Notifications
You must be signed in to change notification settings - Fork 16
/
claude.py
34 lines (31 loc) · 964 Bytes
/
claude.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import aiohttp
import os
ANTHROPIC_HEADERS = {
"X-API-Key": os.environ['ANTHROPIC_API_KEY'],
"Content-Type": "application/json",
}
async def claude_complete(prompt: str, model: str, temperature=0.0):
async with aiohttp.ClientSession() as session:
print('Running claude')
response = await session.post('https://api.anthropic.com/v1/complete',
headers=ANTHROPIC_HEADERS,
json={
"prompt": prompt,
"model": model,
"max_tokens_to_sample": 500,
"temperature": temperature,
# "n": num_tries,
"stream": False,
"stop": "```"
# "logprobs": None,
})
data = await response.json()
# print(repr(data))
completion = data['completion']
if completion.endswith('```'):
completion = completion[:-3]
print(prompt)
print('_____')
print(completion)
print('\n\n\n')
return [completion]