Commit ·
e949b7f
1
Parent(s): 9e54048
correct Claude v1 API usage
Browse files
app.py
CHANGED
|
@@ -29,27 +29,26 @@ class ClaudeServerModel:
|
|
| 29 |
self.model_id = model_id
|
| 30 |
self.temperature = temperature
|
| 31 |
|
| 32 |
-
def complete(self, prompt: str
|
| 33 |
headers = {
|
| 34 |
"x-api-key": self.api_key,
|
| 35 |
"anthropic-version": "2023-06-01",
|
| 36 |
"content-type": "application/json"
|
| 37 |
}
|
|
|
|
| 38 |
body = {
|
| 39 |
"model": self.model_id,
|
| 40 |
"max_tokens": 1024,
|
| 41 |
"temperature": self.temperature,
|
| 42 |
-
"
|
| 43 |
}
|
| 44 |
-
if stop_sequences:
|
| 45 |
-
body["stop_sequences"] = stop_sequences
|
| 46 |
|
| 47 |
-
response = requests.post("https://api.anthropic.com/v1/
|
| 48 |
response.raise_for_status()
|
| 49 |
-
return response.json()["
|
| 50 |
|
| 51 |
-
def __call__(self, prompt: str
|
| 52 |
-
return self.complete(prompt
|
| 53 |
|
| 54 |
# --- Constants ---
|
| 55 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 29 |
self.model_id = model_id
|
| 30 |
self.temperature = temperature
|
| 31 |
|
| 32 |
+
def complete(self, prompt: str) -> str:
|
| 33 |
headers = {
|
| 34 |
"x-api-key": self.api_key,
|
| 35 |
"anthropic-version": "2023-06-01",
|
| 36 |
"content-type": "application/json"
|
| 37 |
}
|
| 38 |
+
|
| 39 |
body = {
|
| 40 |
"model": self.model_id,
|
| 41 |
"max_tokens": 1024,
|
| 42 |
"temperature": self.temperature,
|
| 43 |
+
"prompt": f"\n\nHuman: {prompt}\n\nAssistant:"
|
| 44 |
}
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
response = requests.post("https://api.anthropic.com/v1/complete", headers=headers, json=body)
|
| 47 |
response.raise_for_status()
|
| 48 |
+
return response.json()["completion"].strip()
|
| 49 |
|
| 50 |
+
def __call__(self, prompt: str) -> str:
|
| 51 |
+
return self.complete(prompt)
|
| 52 |
|
| 53 |
# --- Constants ---
|
| 54 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|