diff --git a/app/config.py b/app/config.py
index 1514cc2..ff9851c 100644
--- a/app/config.py
+++ b/app/config.py
@@ -1,3 +1,3 @@
# To be developed
-EVALUATION_CYCLES_COUNT=3
+EVALUATION_CYCLES_COUNT=1
PARSE_ERROR_TRIES = 5
\ No newline at end of file
diff --git a/app/libs/context.py b/app/libs/context.py
index 4e68088..c04a7dc 100644
--- a/app/libs/context.py
+++ b/app/libs/context.py
@@ -58,7 +58,7 @@ def is_tool_call(self):
return bool(
self.last_message["role"] == "user"
and self.tools
- and self.params.get("tool_choice", "none") != "none"
+ and self.params.get("tool_choice", None) != "none"
)
@property
diff --git a/app/libs/tools_handler.py b/app/libs/tools_handler.py
index 261b8e7..a8e5e14 100644
--- a/app/libs/tools_handler.py
+++ b/app/libs/tools_handler.py
@@ -302,7 +302,7 @@ def call_route(messages):
for func in tool_calls:
tool_calls_count[func["name"]] += 1
- pickup_threshold = max(evaluation_cycles_count, int(evaluation_cycles_count * 0.7))
+ pickup_threshold = math.floor(evaluation_cycles_count * 0.7)
final_tool_calls = []
for tool_calls in tool_calls_list:
for func in tool_calls:
diff --git a/app/prompts.py b/app/prompts.py
index cdb0706..15903f6 100644
--- a/app/prompts.py
+++ b/app/prompts.py
@@ -452,11 +452,213 @@ def get_image_desc_guide(ref_index: int, description: str) -> str:
}
""",
},
-]
+ {
+ "input": """# Conversation History:
+
+What was the closing price of Apple Inc. (AAPL) stock yesterday?
+
+
+# Available Tools:
+[
+ {
+ "name": "get_stock_price",
+ "description": "Use this function to retrieve the latest price information for a given stock symbol.\n\n:param symbol: The stock symbol to retrieve the price for (e.g., 'AAPL' for Apple Inc.).\n:return: A string containing the latest price information for the specified stock.",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "symbol": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ {
+ "name": "get_stock_history",
+ "description": "Use this function to retrieve the historical price data for a given stock symbol over a specified period.\n\n:param symbol: The stock symbol to retrieve the historical data for.\n:param period: The time period for the historical data (e.g., '1d', '5d', '1mo', '1y').\n:return: A string containing the historical price data for the specified stock and period.",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "symbol": {
+ "type": "string"
+ },
+ "period": {
+ "type": "string"
+ }
+ }
+ }
+ }
+]""",
+ "output": """
+The user is asking for the closing price of Apple Inc. (AAPL) stock from the previous day. We can use the "get_stock_price" tool to retrieve the latest price information for the AAPL stock symbol. The "get_stock_history" tool is not needed in this case, as the user is only asking for the closing price from yesterday.
+
+
+
+{
+ "tool_calls": [
+ {
+ "name": "get_stock_price",
+ "arguments": {
+ "symbol": "AAPL"
+ }
+ }
+ ]
+}
+""",
+ },
+ {
+ "input": """# Conversation History:
+
+I'm considering investing in Tesla (TSLA) stock. Can you provide me with some information to help me make a decision?
+
+
+To help you make an informed decision about investing in Tesla (TSLA) stock, I can provide you with the following information:
+
+1. Latest price: The current price of TSLA stock can give you an idea of its market value.
+
+2. Historical performance: Analyzing the stock's price history over different periods (e.g., 1 month, 6 months, 1 year) can help you understand its volatility and potential for growth.
+
+3. Company fundamentals: Researching Tesla's financial statements, revenue growth, profitability, and future projects can provide insights into the company's overall health and potential.
+
+4. Market sentiment: Monitoring news, analyst ratings, and investor sentiment can help gauge the market's perception of Tesla stock.
+
+Let me know which specific information you'd like me to provide first, and I'll be happy to assist you further.
+
+
+Thanks for the overview. Let's start with the latest price and the historical performance over the past 6 months. That should give me a good starting point.
+
+
+# Available Tools:
+[
+ {
+ "name": "get_stock_price",
+ "description": "Use this function to retrieve the latest price information for a given stock symbol.\n\n:param symbol: The stock symbol to retrieve the price for (e.g., 'AAPL' for Apple Inc.).\n:return: A string containing the latest price information for the specified stock.",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "symbol": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ {
+ "name": "get_stock_history",
+ "description": "Use this function to retrieve the historical price data for a given stock symbol over a specified period.\n\n:param symbol: The stock symbol to retrieve the historical data for.\n:param period: The time period for the historical data (e.g., '1d', '5d', '1mo', '1y').\n:return: A string containing the historical price data for the specified stock and period.",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "symbol": {
+ "type": "string"
+ },
+ "period": {
+ "type": "string"
+ }
+ }
+ }
+ }
+]""",
+ "output": """
+The user has requested two specific pieces of information to help them make a decision about investing in Tesla (TSLA) stock: the latest price and the historical performance over the past 6 months. To provide this information, we need to use both the "get_stock_price" and "get_stock_history" tools.
+1. "get_stock_price" will be used to retrieve the current price of TSLA stock.
+2. "get_stock_history" will be used to retrieve the price history of TSLA stock over the past 6 months (period: '6mo').
+
+By combining the results from these two tools, we can give the user the requested information to support their investment decision.
+
+
+
+{
+ "tool_calls": [
+ {
+ "name": "get_stock_price",
+ "arguments": {
+ "symbol": "TSLA"
+ }
+ },
+ {
+ "name": "get_stock_history",
+ "arguments": {
+ "symbol": "TSLA",
+ "period": "6mo"
+ }
+ }
+ ]
+}
+""",
+ },
+ {
+ "input": """# Conversation History:
+
+What do you think about the recent performance of the stock market?
+
+
+The stock market's recent performance has been mixed, with some sectors showing strong growth while others have experienced volatility. Here are a few key points:
+
+1. Tech stocks: Many technology companies have seen significant gains, driven by strong earnings and optimism about the sector's long-term prospects.
+
+2. Energy sector: Oil and gas stocks have been under pressure due to fluctuating crude oil prices and concerns about the global economic recovery.
+
+3. Health care: The health care sector has been a mixed bag, with some companies benefiting from the focus on COVID-19 treatments and vaccines, while others have faced challenges.
+
+4. Overall market: The broader stock market indices, such as the S&P 500 and Dow Jones Industrial Average, have reached record highs recently, supported by positive economic data and optimism about the post-pandemic recovery.
+
+It's important to remember that the stock market's performance is influenced by various factors, including economic indicators, geopolitical events, and investor sentiment. As an AI language model, I cannot provide personalized investment advice, but I suggest researching specific sectors and companies, and consulting with a financial advisor before making investment decisions.
+
+
+Thanks for the insights. It's helpful to get a general overview of the market's performance across different sectors. I'll definitely do more research and consult with a financial advisor before making any investment decisions.
+
+
+# Available Tools:
+[
+ {
+ "name": "get_stock_price",
+ "description": "Use this function to retrieve the latest price information for a given stock symbol.\n\n:param symbol: The stock symbol to retrieve the price for (e.g., 'AAPL' for Apple Inc.).\n:return: A string containing the latest price information for the specified stock.",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "symbol": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ {
+ "name": "get_stock_history",
+ "description": "Use this function to retrieve the historical price data for a given stock symbol over a specified period.\n\n:param symbol: The stock symbol to retrieve the historical data for.\n:param period: The time period for the historical data (e.g., '1d', '5d', '1mo', '1y').\n:return: A string containing the historical price data for the specified stock and period.",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "symbol": {
+ "type": "string"
+ },
+ "period": {
+ "type": "string"
+ }
+ }
+ }
+ }
+]""",
+ "output": """
+The user's question about the recent performance of the stock market is broad and does not require the use of the available tools. The conversation history shows that the assistant has provided a general overview of the market's performance across different sectors, which sufficiently addresses the user's question. The user also acknowledges that the insights are helpful and expresses their intention to conduct further research and consult with a financial advisor. As a result, no specific tools are needed to answer this query.
+
+
+
+{
+ "tool_calls": []
+}
+""",
+ },
+]
+import random
def get_suffix():
+ random.shuffle(FEW_SHOTS)
# Turn each element of FEW_SHOTS into a string like '-- EXAMPLE i ---\nINPUT:\n{input}\n\nOUTPUT:\n{output}\n\n', then join them by \n\n
- few_shots = "\n\n".join([f'-- EXAMPLE {i} ---\nINPUT:\n{example["input"]}\n\nOUTPUT:\n{example["output"]}\n\n' for i, example in enumerate(FEW_SHOTS, 1)])
+ few_shots = "\n\n".join(
+ [
+ f'-- EXAMPLE {i} ---\nINPUT:\n{example["input"]}\n\nOUTPUT:\n{example["output"]}\n\n'
+ for i, example in enumerate(FEW_SHOTS, 1)
+ ]
+ )
# Replace FEW_SHOTS with the actual examples
- return SUFFIX.replace("FEW_SHOTS", few_shots)
\ No newline at end of file
+ return SUFFIX.replace("FEW_SHOTS", few_shots)
diff --git a/app/providers.py b/app/providers.py
index 17229c2..99f621d 100644
--- a/app/providers.py
+++ b/app/providers.py
@@ -20,7 +20,7 @@ def clean_params(self, params):
pass
-class OpenAIProvider(BaseProvider):
+class OpenaiProvider(BaseProvider):
def __init__(self, api_key: str, base_url = None):
super().__init__(api_key)
self._client = OpenAI(api_key=api_key)
diff --git a/app/routes/proxy.py b/app/routes/proxy.py
index 22a3769..8d63a1f 100644
--- a/app/routes/proxy.py
+++ b/app/routes/proxy.py
@@ -34,6 +34,15 @@ async def get_openai_v1(
return JSONResponse(content={"message": f"GET request to {provider} v1"})
+@router.post("/groqchain/{provider}/v1/chat/completions")
+async def post_groq_chat_completions(
+ request: Request,
+ provider: str = Path(..., title="Provider")
+) -> JSONResponse:
+ # Call the original post_chat_completions method with provider set to "groq"
+ return await post_chat_completions(request, provider="groq")
+
+
@router.post("/{provider}/v1/chat/completions")
async def post_chat_completions(
request: Request,
diff --git a/app/utils.py b/app/utils.py
index ca46f40..fcdf2ad 100644
--- a/app/utils.py
+++ b/app/utils.py
@@ -42,7 +42,7 @@ def get_tool_call_response(tool_calls_result, unresolved_tol_calls, resolved_res
"index": 0,
"message": {
"role": "assistant",
- "content": None,
+ "content": "", # None,
"tool_calls": unresolved_tol_calls,
},
"logprobs": None,
diff --git a/cookbook/functiona_call_groq_langchain.py b/cookbook/functiona_call_groq_langchain.py
new file mode 100644
index 0000000..69fefb7
--- /dev/null
+++ b/cookbook/functiona_call_groq_langchain.py
@@ -0,0 +1,53 @@
+# pip install --upgrade --quiet langchain-groq tavily-python langchain langchainhub langchain-openai
+
+from langchain_core.prompts import ChatPromptTemplate
+from langchain_groq import ChatGroq
+import os
+from dotenv import load_dotenv
+load_dotenv()
+from langchain import hub
+from langchain.agents import create_openai_tools_agent
+from langchain_community.tools.tavily_search import TavilySearchResults, TavilyAnswer
+from langchain.agents import AgentExecutor
+
+# The following code raise an error.
+chat = ChatGroq(
+ temperature=0,
+ groq_api_key=os.environ["GROQ_API_KEY"],
+ model_name="mixtral-8x7b-32768",
+)
+
+prompt = hub.pull("hwchase17/openai-tools-agent")
+tools = [TavilySearchResults(max_results=1)]
+agent = create_openai_tools_agent(chat, tools, prompt)
+
+agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, stream_runnable = False)
+agent_executor.invoke({"input": "What is Langchain?"})
+
+
+# The following code works fine using GroqCall (Funckycall) proxy
+chat = ChatGroq(
+ temperature=0,
+ groq_api_key=os.environ["GROQ_API_KEY"],
+ model_name="mixtral-8x7b-32768",
+ groq_api_base= "http://localhost:8000/proxy/groqchain"
+ # groq_api_base= "http://groqcall.ai/proxy/groqchain"
+)
+
+# Example 1: Chat with tools
+prompt = hub.pull("hwchase17/openai-tools-agent")
+tools = [TavilySearchResults(max_results=1)]
+agent = create_openai_tools_agent(chat, tools, prompt)
+
+agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, stream_runnable = False)
+result = agent_executor.invoke({"input": "What is Langchain?"})
+print(result)
+
+# Example 1: Simple chat
+system = "You are a helpful assistant."
+human = "{text}"
+prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])
+
+chain = prompt | chat
+result = chain.invoke({"text": "Explain the importance of low latency LLMs."})
+print(result)