Skip to content

Commit

Permalink
Merge pull request #541 from 3rd-Son/testrefactor
Browse files Browse the repository at this point in the history
added skipifs and fixture to test in community
  • Loading branch information
cobycloud authored Sep 26, 2024
2 parents 3301386 + 6fd6a52 commit 06c48a3
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 315 deletions.
5 changes: 2 additions & 3 deletions pkgs/community/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"neo4j",
"swarmauri-core==0.5.0.dev8",
"swarmauri==0.5.0.dev8",
"pygithub",
],
extras_require={
"full": [
Expand Down Expand Up @@ -64,9 +65,7 @@
"tf-keras",
"pinecone",
"neo4j",
"tiktoken"


"tiktoken",
]
},
classifiers=[
Expand Down
205 changes: 124 additions & 81 deletions pkgs/community/swarmauri_community/llms/concrete/ShuttleAIModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,97 +5,140 @@

from swarmauri.messages.base.MessageBase import MessageBase
from swarmauri.messages.concrete.AgentMessage import AgentMessage
from swarmauri.llms.base.LLMBase import LLMBase
from swarmauri.llms.base.LLMBase import LLMBase

import requests

import requests

class ShuttleAIModel(LLMBase):
api_key: str
allowed_models: List[str] = [
"shuttle-2-turbo", "shuttle-turbo", "gpt-4o-2024-05-13", "gpt-4-turbo-2024-04-09",
"gpt-4-0125-preview", "gpt-4-1106-preview", "gpt-4-1106-vision-preview", "gpt-4-0613",
"gpt-4-bing", "gpt-4-turbo-bing", "gpt-4-32k-0613", "gpt-3.5-turbo-0125",
"gpt-3.5-turbo-1106", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307",
"claude-2.1", "claude-2.0", "claude-instant-1.2", "claude-instant-1.1",
"claude-instant-1.0", "meta-llama-3-70b-instruct", "meta-llama-3-8b-instruct", "llama-3-sonar-large-32k-online",
"llama-3-sonar-small-32k-online", "llama-3-sonar-large-32k-chat", "llama-3-sonar-small-32k-chat", "blackbox",
"blackbox-code", "wizardlm-2-8x22b", "wizardlm-2-70b", "dolphin-2.6-mixtral-8x7b",
"codestral-latest", "mistral-large", "mistral-next", "mistral-medium",
"mistral-small", "mistral-tiny", "mixtral-8x7b-instruct-v0.1", "mixtral-8x22b-instruct-v0.1",
"mistral-7b-instruct-v0.2", "mistral-7b-instruct-v0.1", "nous-hermes-2-mixtral-8x7b", "gemini-1.5-pro-latest",
"gemini-1.0-pro-latest", "gemini-1.0-pro-vision", "lzlv-70b", "figgs-rp", "cinematika-7b"
"blackbox",
"blackbox-code",
"cinematika-7b",
"claude-2.0",
"claude-2.1",
"claude-3-haiku-20240307",
"claude-3-opus-20240229",
"claude-3-sonnet-20240229",
"claude-instant-1.0",
"claude-instant-1.1",
"claude-instant-1.2",
"codestral-latest",
"dolphin-2.6-mixtral-8x7b",
"figgs-rp",
"gemini-1.0-pro-latest",
"gemini-1.0-pro-vision",
"gemini-1.5-pro-latest",
"gpt-3.5-turbo-0125",
"gpt-3.5-turbo-1106",
"gpt-4-0125-preview",
"gpt-4-0613",
"gpt-4-1106-preview",
"gpt-4-1106-vision-preview",
"gpt-4-bing",
"gpt-4-turbo-2024-04-09",
"gpt-4-turbo-bing",
"gpt-4o-2024-05-13",
"gpt-4-32k-0613",
"llama-3-sonar-large-32k-chat",
"llama-3-sonar-large-32k-online",
"llama-3-sonar-small-32k-chat",
"llama-3-sonar-small-32k-online",
"lzlv-70b",
"meta-llama-3-70b-instruct",
"meta-llama-3-8b-instruct",
"mistral-7b-instruct-v0.1",
"mistral-7b-instruct-v0.2",
"mistral-large",
"mistral-medium",
"mistral-next",
"mistral-small",
"mistral-tiny",
"mixtral-8x22b-instruct-v0.1",
"mixtral-8x7b-instruct-v0.1",
"nous-hermes-2-mixtral-8x7b",
"shuttle-2-turbo",
"shuttle-turbo",
"wizardlm-2-70b",
"wizardlm-2-8x22b",
]
name: str = "shuttle-2-turbo"
type: Literal['ShuttleAIModel'] = 'ShuttleAIModel'
type: Literal["ShuttleAIModel"] = "ShuttleAIModel"

def _format_messages(self, messages: List[SubclassUnion[MessageBase]]) -> List[Dict[str, str]]:
# Get only the properties that we require
def _format_messages(
self, messages: List[SubclassUnion[MessageBase]]
) -> List[Dict[str, str]]:
# Get only the properties that we require
message_properties = ["content", "role"]

# Exclude FunctionMessages
formatted_messages = [message.model_dump(include=message_properties) for message in messages]
formatted_messages = [
message.model_dump(include=message_properties) for message in messages
]
return formatted_messages


def predict(self,
conversation,
temperature=0.7,
max_tokens=256,
top_p=1,
internet=False,
citations=False,
tone='precise',
raw=False,
image=None):

formatted_messages = self._format_messages(conversation.history)

url = "https://api.shuttleai.app/v1/chat/completions"
payload = {
"model": self.name,
"messages": formatted_messages,
"max_tokens": max_tokens,
"temperature": temperature,
"top_p": top_p
}

if raw:
payload['raw'] = True

if internet:
payload['internet'] = True

# Only include the 'image' field if it's not None
if image is not None:
payload["image"] = image

if self.name in ['gpt-4-bing', 'gpt-4-turbo-bing']:
payload['tone'] = tone

# Include citations only if citations is True
if citations:
payload['citations'] = True

headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}

# Log payload for debugging
logging.info(f"Payload being sent: {payload}")

# Send the request
response = requests.post(url, json=payload, headers=headers)

# Log response for debugging
logging.info(f"Response received: {response.text}")

# Parse response JSON safely
try:
message_content = response.json()['choices'][0]['message']['content']
except KeyError as e:
logging.info(f"Error parsing response: {response.text}")
raise e

conversation.add_message(AgentMessage(content=message_content))
return conversation
def predict(
self,
conversation,
temperature=0.7,
max_tokens=256,
top_p=1,
internet=False,
citations=False,
tone="precise",
raw=False,
image=None,
):

formatted_messages = self._format_messages(conversation.history)

url = "https://api.shuttleai.app/v1/chat/completions"
payload = {
"model": self.name,
"messages": formatted_messages,
"max_tokens": max_tokens,
"temperature": temperature,
"top_p": top_p,
}

if raw:
payload["raw"] = True

if internet:
payload["internet"] = True

# Only include the 'image' field if it's not None
if image is not None:
payload["image"] = image

if self.name in ["gpt-4-bing", "gpt-4-turbo-bing"]:
payload["tone"] = tone

# Include citations only if citations is True
if citations:
payload["citations"] = True

headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}

# Log payload for debugging
logging.info(f"Payload being sent: {payload}")

# Send the request
response = requests.post(url, json=payload, headers=headers)

# Log response for debugging
logging.info(f"Response received: {response.text}")

# Parse response JSON safely
try:
message_content = response.json()["choices"][0]["message"]["content"]
except KeyError as e:
logging.info(f"Error parsing response: {response.text}")
raise e

conversation.add_message(AgentMessage(content=message_content))
return conversation
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
class ShuttleAIToolModel(LLMBase):
api_key: str
allowed_models: List[str] = [
"shuttle-2-turbo",
"gpt-4-turbo-2024-04-09",
"gpt-4-0125-preview",
"gpt-4-1106-preview",
"gpt-4-0613",
"claude-instant-1.1",
"gemini-1.0-pro-latest",
"gemini-1.5-pro-latest",
"gpt-3.5-turbo-0125",
"gpt-3.5-turbo-1106",
"claude-instant-1.1",
"wizardlm-2-8x22b",
"gpt-4-0125-preview",
"gpt-4-0613",
"gpt-4-1106-preview",
"gpt-4-turbo-2024-04-09",
"mistral-7b-instruct-v0.2",
"gemini-1.5-pro-latest",
"gemini-1.0-pro-latest",
"shuttle-2-turbo",
"wizardlm-2-8x22b",
]
name: str = "shuttle-2-turbo"
type: Literal["ShuttleAIToolModel"] = "ShuttleAIToolModel"
Expand Down Expand Up @@ -95,11 +95,10 @@ def predict(
payload["tone"] = tone
# Include citations only if citations is True
if citations:
payload['citations'] = True

payload["citations"] = True

logging.info(f"payload: {payload}")

# First we ask agent to give us a response
agent_response = requests.request("POST", url, json=payload, headers=headers)

Expand All @@ -117,32 +116,28 @@ def predict(
"tool_calls", None
)


# If agent responds with tool call, then we execute the functions
if tool_calls:
for tool_call in tool_calls:
func_name = tool_call["function"]["name"]
func_call = toolkit.get_tool_by_name(func_name)
func_args = json.loads(tool_call["function"]["arguments"])
func_result = func_call(**func_args)
func_message = FunctionMessage(content=func_result,
name=func_name,
tool_call_id=tool_call['id'])
func_message = FunctionMessage(
content=func_result, name=func_name, tool_call_id=tool_call["id"]
)
conversation.add_message(func_message)



logging.info(f"conversation: {conversation.history}")


# After executing the functions, we present the results to the Agent
payload['messages'] = self._format_messages(conversation.history)
payload["messages"] = self._format_messages(conversation.history)

logging.info(f"payload: {payload}")

agent_response = requests.request("POST", url, json=payload, headers=headers)
logging.info(f"agent response {agent_response.json()}")

agent_message = AgentMessage(
content=agent_response.json()["choices"][0]["message"]["content"]
)
Expand Down
Loading

0 comments on commit 06c48a3

Please sign in to comment.