eaglelandsonce commited on
Commit
8d0b33d
·
verified ·
1 Parent(s): c3fc1bb

Update crewai/tools/anthropic_tools.py

Browse files
Files changed (1) hide show
  1. crewai/tools/anthropic_tools.py +11 -32
crewai/tools/anthropic_tools.py CHANGED
@@ -11,7 +11,8 @@ if not ANTHROPIC_API_KEY:
11
  from langchain.tools import tool
12
 
13
  # Initialize the Anthropic client
14
- client = anthropic.Client(ANTHROPIC_API_KEY)
 
15
 
16
  class AnthropicSearchTools:
17
  @tool("Anthropic search the internet")
@@ -25,41 +26,19 @@ class AnthropicSearchTools:
25
  Returns:
26
  str: The response text from the Anthropic model or an error message.
27
  """
 
28
  try:
29
- response = client.completions.create(
30
- prompt=query,
31
- max_tokens_to_sample=500,
32
- model="claude-v1",
33
- stop_sequences=[],
34
- )
35
- return response.completion
36
 
37
  except Exception as e:
38
  # Handle any exceptions here
39
  print(f"Error: {str(e)}")
40
  return "Error: An unexpected error occurred. Please try again later."
41
 
42
- @tool("Anthropic search news on the internet")
43
- def anthropic_search_news(query):
44
- """
45
- Searches for news content based on the provided query using the Anthropic model.
46
-
47
- Args:
48
- query (str): The search query.
49
-
50
- Returns:
51
- str: The response text from the Anthropic model or an error message.
52
- """
53
- try:
54
- response = client.completions.create(
55
- prompt=f"Search for news about: {query}",
56
- max_tokens_to_sample=500,
57
- model="claude-v1",
58
- stop_sequences=[],
59
- )
60
- return response.completion
61
-
62
- except Exception as e:
63
- # Handle any exceptions here
64
- print(f"Error: {str(e)}")
65
- return "Error: An unexpected error occurred. Please try again later."
 
11
  from langchain.tools import tool
12
 
13
  # Initialize the Anthropic client
14
+ #client = anthropic.Client(ANTHROPIC_API_KEY)
15
+ client = anthropic.Anthropic(api_key=ANTHROPIC_API_KEY)
16
 
17
  class AnthropicSearchTools:
18
  @tool("Anthropic search the internet")
 
26
  Returns:
27
  str: The response text from the Anthropic model or an error message.
28
  """
29
+
30
  try:
31
+ response = client.messages.create(
32
+ model="claude-3-opus-20240229",
33
+ max_tokens=1024,
34
+ messages=[
35
+ {"role": "user", "content": query}
36
+ )
37
+ return message.content
38
 
39
  except Exception as e:
40
  # Handle any exceptions here
41
  print(f"Error: {str(e)}")
42
  return "Error: An unexpected error occurred. Please try again later."
43
 
44
+