Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -38,7 +38,44 @@ class ClaudeLLM(LLM):
|
|
| 38 |
return {
|
| 39 |
|
| 40 |
}
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def remove_numbers(question):
|
| 43 |
return question.translate(str.maketrans('', '', '0123456789'))
|
| 44 |
|
|
|
|
| 38 |
return {
|
| 39 |
|
| 40 |
}
|
| 41 |
+
|
| 42 |
+
class ClaudeLLM2(LLM):
|
| 43 |
+
|
| 44 |
+
@property
|
| 45 |
+
def _llm_type(self) -> str:
|
| 46 |
+
|
| 47 |
+
return "custom"
|
| 48 |
+
|
| 49 |
+
def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
client = Anthropic(
|
| 53 |
+
# defaults to os.environ.get("ANTHROPIC_API_KEY")
|
| 54 |
+
api_key= os.environ.get("ANTHROPIC_API_KEY"),
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# How about the formatted prompt?
|
| 59 |
+
prompt_formatted = (
|
| 60 |
+
f"{HUMAN_PROMPT}{prompt}\n{AI_PROMPT}"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
response = client.completions.create(
|
| 64 |
+
model="claude-2",
|
| 65 |
+
prompt=prompt_formatted,
|
| 66 |
+
stop_sequences=[HUMAN_PROMPT],
|
| 67 |
+
max_tokens_to_sample=100000,
|
| 68 |
+
temperature=0,
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
return response.completion
|
| 72 |
+
|
| 73 |
+
@property
|
| 74 |
+
def _identifying_params(self) -> Mapping[str, Any]:
|
| 75 |
+
"""Get the identifying parameters."""
|
| 76 |
+
return {
|
| 77 |
+
|
| 78 |
+
}
|
| 79 |
def remove_numbers(question):
|
| 80 |
return question.translate(str.maketrans('', '', '0123456789'))
|
| 81 |
|