Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:No changes made in the pull request. #125

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libs/Cohere/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ paths:
code: "const { CohereClientV2 } = require('cohere-ai');\n\nconst cohere = new CohereClientV2({});\n\n(async () => {\n const response = await cohere.chat({\n model: 'command-r-plus-08-2024',\n tools: [\n {\n type: 'function',\n function: {\n name: 'query_daily_sales_report',\n description:\n 'Connects to a database to retrieve overall sales volumes and sales information for a given day.',\n parameters: {\n type: 'object',\n properties: {\n day: {\n description: 'Retrieves sales data for this day, formatted as YYYY-MM-DD.',\n type: 'string',\n },\n },\n },\n },\n },\n {\n type: 'function',\n function: {\n name: 'query_product_catalog',\n description:\n 'Connects to a a product catalog with information about all the products being sold, including categories, prices, and stock levels.',\n parameters: {\n type: 'object',\n properties: {\n category: {\n description:\n 'Retrieves product information data for all products in this category.',\n type: 'string',\n },\n },\n },\n },\n },\n ],\n messages: [\n {\n role: 'user',\n content:\n \"Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?\",\n },\n ],\n });\n\n console.log(response);\n})();\n"
- sdk: python
name: Tools
code: "import cohere\n\nco = cohere.Client()\n\nresponse = co.chat(\n model=\"command-r-plus-08-2024\",\n tools=[\n cohere.ToolV2(\n type=\"function\",\n function={\n \"name\": \"query_daily_sales_report\",\n \"description\": \"Connects to a database to retrieve overall sales volumes and sales information for a given day.\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"day\": {\n \"description\": \"Retrieves sales data for this day, formatted as YYYY-MM-DD.\",\n \"type\": \"string\",\n }\n },\n },\n },\n ),\n cohere.ToolV2(\n type=\"function\",\n function={\n \"name\": \"query_product_catalog\",\n \"description\": \"Connects to a a product catalog with information about all the products being sold, including categories, prices, and stock levels.\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"category\": {\n \"description\": \"Retrieves product information data for all products in this category.\",\n \"type\": \"string\",\n }\n },\n },\n },\n ),\n ],\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?\",\n }\n ],\n)\n\nprint(response)\n"
code: "import cohere\n\nco = cohere.ClientV2()\n\nresponse = co.chat(\n model=\"command-r-plus-08-2024\",\n tools=[\n cohere.ToolV2(\n type=\"function\",\n function={\n \"name\": \"query_daily_sales_report\",\n \"description\": \"Connects to a database to retrieve overall sales volumes and sales information for a given day.\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"day\": {\n \"description\": \"Retrieves sales data for this day, formatted as YYYY-MM-DD.\",\n \"type\": \"string\",\n }\n },\n },\n },\n ),\n cohere.ToolV2(\n type=\"function\",\n function={\n \"name\": \"query_product_catalog\",\n \"description\": \"Connects to a a product catalog with information about all the products being sold, including categories, prices, and stock levels.\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"category\": {\n \"description\": \"Retrieves product information data for all products in this category.\",\n \"type\": \"string\",\n }\n },\n },\n },\n ),\n ],\n messages=[\n {\n \"role\": \"user\",\n \"content\": \"Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?\",\n }\n ],\n)\n\nprint(response)\n"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve Python example with proper error handling and client initialization

The Python example should follow best practices for production use:

 import cohere
+import os
+from contextlib import contextmanager
 
-co = cohere.ClientV2()
+@contextmanager
+def get_cohere_client():
+    client = cohere.ClientV2(api_key=os.environ.get("COHERE_API_KEY"))
+    try:
+        yield client
+    finally:
+        client.close()
 
-response = co.chat(
-    model="command-r-plus-08-2024",
-    tools=[
-        # ... tools configuration ...
-    ],
-    messages=[
-        # ... messages ...
-    ],
-)
+def main():
+    try:
+        with get_cohere_client() as co:
+            response = co.chat(
+                model="command-r-plus-08-2024",
+                tools=[
+                    # ... tools configuration ...
+                ],
+                messages=[
+                    # ... messages ...
+                ],
+            )
+            print(response)
+    except cohere.CohereError as e:
+        print(f"Error calling Cohere API: {e}")
+        raise
 
-print(response)
+if __name__ == "__main__":
+    main()

Committable suggestion skipped: line range outside the PR's diff.

- sdk: java
name: Tools
code: "/* (C)2024 */\npackage chatv2post;\n\nimport com.cohere.api.Cohere;\nimport com.cohere.api.resources.v2.requests.V2ChatRequest;\nimport com.cohere.api.types.*;\nimport java.util.List;\nimport java.util.Map;\n\npublic class Tools {\n public static void main(String[] args) {\n Cohere cohere = Cohere.builder().clientName(\"snippet\").build();\n\n ChatResponse response =\n cohere\n .v2()\n .chat(\n V2ChatRequest.builder()\n .model(\"command-r-plus-08-2024\")\n .tools(\n List.of(\n ToolV2.builder()\n .function(\n ToolV2Function.builder()\n .name(\"query_daily_sales_report\")\n .description(\n \"Connects\"\n + \" to a\"\n + \" database\"\n + \" to retrieve\"\n + \" overall\"\n + \" sales\"\n + \" volumes\"\n + \" and sales\"\n + \" information\"\n + \" for a\"\n + \" given\"\n + \" day.\")\n .parameters(\n Map.of(\n \"day\",\n ToolParameterDefinitionsValue.builder()\n .type(\"str\")\n .description(\n \"Retrieves\"\n + \" sales\"\n + \" data\"\n + \" for this\"\n + \" day,\"\n + \" formatted\"\n + \" as YYYY-MM-DD.\")\n .required(true)\n .build()))\n .build())\n .build(),\n ToolV2.builder()\n .function(\n ToolV2Function.builder()\n .name(\"query_product_catalog\")\n .description(\n \"Connects\"\n + \" to a\"\n + \" a product\"\n + \" catalog\"\n + \" with\"\n + \" information\"\n + \" about\"\n + \" all the\"\n + \" products\"\n + \" being\"\n + \" sold,\"\n + \" including\"\n + \" categories,\"\n + \" prices,\"\n + \" and stock\"\n + \" levels.\")\n .parameters(\n Map.of(\n \"category\",\n ToolParameterDefinitionsValue.builder()\n .type(\"str\")\n .description(\n \"Retrieves\"\n + \" product\"\n + \" information\"\n + \" data\"\n + \" for all\"\n + \" products\"\n + \" in this\"\n + \" category.\")\n .required(true)\n .build()))\n .build())\n .build()))\n .build());\n\n System.out.println(response);\n }\n}\n"
Expand Down
Loading