Skip to content

Commit fe7ae3b

Browse files
author
Kye
committed
clean up + anthropic
1 parent 02c9286 commit fe7ae3b

12 files changed

Lines changed: 54 additions & 220 deletions

example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from tree_of_thoughts.openai_models import OpenAILanguageModel
2+
from tree_of_thoughts.models.openai_models import OpenAILanguageModel
33
from tree_of_thoughts.treeofthoughts import MonteCarloTreeofThoughts
44

55

examples/example_tot2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from tree_of_thoughts.openai_models import OpenAILanguageModel
1+
from tree_of_thoughts.models.openai_models import OpenAILanguageModel
22
from tree_of_thoughts.treeofthoughts import TreeofThoughts2
33
#
44

examples/example_totA.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from tree_of_thoughts.openai_models import OpenAILanguageModel
1+
from tree_of_thoughts.models.openai_models import OpenAILanguageModel
22
from tree_of_thoughts.treeofthoughts import TreeofThoughtsASearch
33
#
44

examples/example_totdfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from tree_of_thoughts.openai_models import OpenAILanguageModel
1+
from tree_of_thoughts.models.openai_models import OpenAILanguageModel
22
from tree_of_thoughts.treeofthoughts import TreeofThoughtsDFS
33
#
44

examples/montecarlo_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from tree_of_thoughts.openai_models import OpenAILanguageModel
1+
from tree_of_thoughts.models.openai_models import OpenAILanguageModel
22
from tree_of_thoughts.treeofthoughts import MonteCarloTreeofThoughts
33

44

tree_of_thoughts/agent/master.py

Lines changed: 0 additions & 212 deletions
This file was deleted.

tree_of_thoughts/models/__init__.py

Whitespace-only changes.
File renamed without changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import requests
2+
import os
3+
4+
class Anthropic:
5+
"""Anthropic large language models."""
6+
7+
def __init__(self, model="claude-2", max_tokens_to_sample=256, temperature=None, top_k=None, top_p=None, streaming=False, default_request_timeout=None):
8+
self.model = model
9+
self.max_tokens_to_sample = max_tokens_to_sample
10+
self.temperature = temperature
11+
self.top_k = top_k
12+
self.top_p = top_p
13+
self.streaming = streaming
14+
self.default_request_timeout = default_request_timeout or 600
15+
self.anthropic_api_url = os.getenv("ANTHROPIC_API_URL", "https://api.anthropic.com")
16+
self.anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
17+
18+
def _default_params(self):
19+
"""Get the default parameters for calling Anthropic API."""
20+
d = {
21+
"max_tokens_to_sample": self.max_tokens_to_sample,
22+
"model": self.model,
23+
}
24+
if self.temperature is not None:
25+
d["temperature"] = self.temperature
26+
if self.top_k is not None:
27+
d["top_k"] = self.top_k
28+
if self.top_p is not None:
29+
d["top_p"] = self.top_p
30+
return d
31+
32+
def _call(self, prompt, stop=None):
33+
"""Call out to Anthropic's completion endpoint."""
34+
stop = stop or []
35+
params = self._default_params()
36+
headers = {"Authorization": f"Bearer {self.anthropic_api_key}"}
37+
data = {
38+
"prompt": prompt,
39+
"stop_sequences": stop,
40+
**params
41+
}
42+
response = requests.post(f"{self.anthropic_api_url}/completions", headers=headers, json=data, timeout=self.default_request_timeout)
43+
return response.json().get("completion")
44+
45+
46+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import guidance
2-
from tree_of_thoughts.abstract_language_model import AbstractLanguageModel
2+
from tree_of_thoughts.models.abstract_language_model import AbstractLanguageModel
33
import time
44
import os
55
import openai

0 commit comments

Comments
 (0)