Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -1,8 +1,11 @@
|
|
1 |
from langchain.llms.base import LLM
|
2 |
from typing import Optional, List, Mapping, Any
|
3 |
-
|
|
|
|
|
4 |
from urllib.parse import urlparse
|
5 |
import os
|
|
|
6 |
class ClaudeLLM(LLM):
|
7 |
|
8 |
@property
|
@@ -13,24 +16,26 @@ class ClaudeLLM(LLM):
|
|
13 |
def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
|
14 |
|
15 |
|
16 |
-
client =
|
|
|
|
|
|
|
17 |
|
18 |
|
19 |
# How about the formatted prompt?
|
20 |
prompt_formatted = (
|
21 |
-
f"{
|
22 |
)
|
23 |
|
24 |
-
|
25 |
-
response = client.completion(
|
26 |
-
prompt=prompt_formatted,
|
27 |
-
stop_sequences=[anthropic.HUMAN_PROMPT],
|
28 |
model="claude-instant-v1-100k",
|
|
|
|
|
29 |
max_tokens_to_sample=100000,
|
30 |
-
temperature=0
|
31 |
)
|
32 |
|
33 |
-
return response
|
34 |
|
35 |
@property
|
36 |
def _identifying_params(self) -> Mapping[str, Any]:
|
@@ -38,6 +43,7 @@ class ClaudeLLM(LLM):
|
|
38 |
return {
|
39 |
|
40 |
}
|
|
|
41 |
|
42 |
class ClaudeLLM2(LLM):
|
43 |
|
|
|
1 |
from langchain.llms.base import LLM
|
2 |
from typing import Optional, List, Mapping, Any
|
3 |
+
|
4 |
+
from anthropic import Anthropic, HUMAN_PROMPT, AI_PROMPT
|
5 |
+
|
6 |
from urllib.parse import urlparse
|
7 |
import os
|
8 |
+
|
9 |
class ClaudeLLM(LLM):
|
10 |
|
11 |
@property
|
|
|
16 |
def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
|
17 |
|
18 |
|
19 |
+
client = Anthropic(
|
20 |
+
# defaults to os.environ.get("ANTHROPIC_API_KEY")
|
21 |
+
api_key= os.environ.get("ANTHROPIC_API_KEY"),
|
22 |
+
)
|
23 |
|
24 |
|
25 |
# How about the formatted prompt?
|
26 |
prompt_formatted = (
|
27 |
+
f"{HUMAN_PROMPT}{prompt}\n{AI_PROMPT}"
|
28 |
)
|
29 |
|
30 |
+
response = client.completions.create(
|
|
|
|
|
|
|
31 |
model="claude-instant-v1-100k",
|
32 |
+
prompt=prompt_formatted,
|
33 |
+
stop_sequences=[HUMAN_PROMPT],
|
34 |
max_tokens_to_sample=100000,
|
35 |
+
temperature=0,
|
36 |
)
|
37 |
|
38 |
+
return response.completion
|
39 |
|
40 |
@property
|
41 |
def _identifying_params(self) -> Mapping[str, Any]:
|
|
|
43 |
return {
|
44 |
|
45 |
}
|
46 |
+
|
47 |
|
48 |
class ClaudeLLM2(LLM):
|
49 |
|