{"id":20785985,"url":"https://github.com/thomassuedbroecker/function_calling_langchain_watsonx_example","last_synced_at":"2026-03-03T06:36:22.727Z","repository":{"id":252803275,"uuid":"841350143","full_name":"thomassuedbroecker/function_calling_langchain_watsonx_example","owner":"thomassuedbroecker","description":"This is an example using the langchain_ibm implementation for function calling a LLM model running in watsonx.","archived":false,"fork":false,"pushed_at":"2024-08-15T08:08:33.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-11T12:37:26.190Z","etag":null,"topics":["ai","function-calling","langchain","python","watsonx"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomassuedbroecker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-12T08:27:25.000Z","updated_at":"2024-08-15T08:08:36.000Z","dependencies_parsed_at":"2024-11-17T14:50:08.861Z","dependency_job_id":"58b87612-6149-458c-903e-23added7a888","html_url":"https://github.com/thomassuedbroecker/function_calling_langchain_watsonx_example","commit_stats":null,"previous_names":["thomassuedbroecker/function_calling_langchain_watsonx_example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thomassuedbroecker/function_calling_langchain_watsonx_example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Ffunction_calling_langchain_watsonx_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Ffunction_calling_langchain_watsonx_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Ffunction_calling_langchain_watsonx_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Ffunction_calling_langchain_watsonx_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomassuedbroecker","download_url":"https://codeload.github.com/thomassuedbroecker/function_calling_langchain_watsonx_example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomassuedbroecker%2Ffunction_calling_langchain_watsonx_example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30034111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T06:09:21.518Z","status":"ssl_error","status_checked_at":"2026-03-03T06:08:47.858Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","function-calling","langchain","python","watsonx"],"created_at":"2024-11-17T14:49:55.389Z","updated_at":"2026-03-03T06:36:22.708Z","avatar_url":"https://github.com/thomassuedbroecker.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# function_calling_langchain_watsonx_example\n\nThis repository is an example using the `langchain_ibm` implementation for function calling with watsonx.\n\nRelated blog post: [Integrating langchain_ibm with watsonx and LangChain: Example and Tutorial](https://wp.me/paelj4-20d)\n\n## Setup and run the example\n\nThe following steps are instructions on how to run the example on your local machine.\n\n### Step 1: Clone the repository to your local machine\n```sh\ngit clone https://github.com/thomassuedbroecker/function_calling_langchain_watsonx_example.git\n```\n\n### Step 2: Generate a virtual Python environment\n\n```sh\ncd code\npython3 -m venv --upgrade-deps venv\nsource venv/bin/activate\n```\n\n### Step 3: Install the needed libraries\n\n```sh \npython3 -m pip install -qU langchain-ibm\npython3 -m pip install python-weather\n```\n\n### Step 4: Generate a `.env` file for the needed environment variables\n\n```sh\ncat env_example_template \u003e .env\n```\n\nInsert the values for the two environment variables: \n\n* `WATSONX_PROJECT_ID=YOUR_WATSONX_PROJECT_ID`\n* `IBMCLOUD_APIKEY=YOUR_KEY`\n\nContent of the environment file.\n\n```sh\nexport IBMCLOUD_APIKEY=YOUR_KEY\nexport IBMCLOUD_URL=\"https://iam.cloud.ibm.com/identity/token\"\n\n# Watsonx\nexport WATSONX_URL=\"https://eu-de.ml.cloud.ibm.com\"\nexport WATSONX_VERSION=2023-05-29\nexport WATSONX_PROJECT_ID=YOUR_PROJECT_ID\n\nexport WATSONX_MIN_NEW_TOKENS=1\nexport WATSONX_MAX_NEW_TOKENS=300\nexport WATSONX_LLM_NAME=mistralai/mixtral-8x7b-instruct-v01\nexport WATSONX_INSTANCE_ID=YOUR_WATSONX_INSTANCE_ID\n```\n\n### Step 5: Run the example\n\n```sh\nbash example_function_invocation.sh\n```\n\n* Output of the invocation:\n\n```\n##########################\n# 0. Load environments\n##########################\n# 1. Invoke application\n1. Load environment\n{'project_id': 'YOUR_PROJECT_ID', 'url': 'https://eu-de.ml.cloud.ibm.com', 'model_id': 'mistralai/mixtral-8x7b-instruct-v01', 'apikey': 'YOUR_APIKEY'}\n\n2. Prepare model parameters\n{'decoding_method': 'greedy', 'max_new_tokens': 400, 'min_new_tokens': 1, 'temperature': 1.0}\n\n3. Create a ChatWatsonx instance\n\n4. Bind tools to chat\n\n5. Run the weather example\n\n- Weather_messages:\n[('system', \"You are a weather expert. If the question is not about the weather, say: I don't know.\"), ('human', 'Which city is hotter today: LA or NY?')]\n\n- Weather_aimessage:\ncontent='' additional_kwargs={'tool_calls': {'type': 'function', 'function': {'name': 'weather_service', 'arguments': {'city': 'LA, NY'}}}} response_metadata={'token_usage': {'generated_token_count': 65, 'input_token_count': 723}, 'model_name': 'mistralai/mixtral-8x7b-instruct-v01', 'system_fingerprint': '', 'finish_reason': 'stop_sequence'} id='run-6893b0a4-85cb-44fd-8500-fd44c35def5e-0' tool_calls=[{'name': 'weather_service', 'args': {'city': 'LA, NY'}, 'id': '1723450740.908', 'type': 'tool_call'}] usage_metadata={'input_tokens': 723, 'output_tokens': 65, 'total_tokens': 788}\n\n- Weather_tools:\n[{'name': 'weather_service', 'args': {'city': 'LA, NY'}, 'id': '1723450740.908', 'type': 'tool_call'}]\n\n- Invoke real weather endpoint:\n[{'city': 'LA', 'temperature': '11 celsius'}, {'city': ' NY', 'temperature': '13 celsius'}]\n\n\n6. Run the finance example\n\n- Finance_messages:\n[('system', 'You are a finance expert tasked with analyzing the questions and selecting the most relevant title from a specified table. Find the finance topic and finance category that best match the content of the sentence.\\n        **Dictionary:**\\n        {categories}\\n        **Instructions:**\\n        - Determine the correct table from the dictionary.\\n        - Use this table to find the finance topic and finance category values that are most relevant to the finance sentence\\n        - Ensure that the values retrieved are the best match to the content of the sentence.\\n        **Conclusion:**\\n        Provide the result in the following format, only return following information not add any other word or sentence in response, give answer only in JSON Object format, only return answer with the following format do not use different format:\\n        {{\"category\": \"found_category\", \"id\": category_id}}\\n        '), ('human', 'What percentage of total Debit Card and Credit Card expenditures were made in the Airlines and Accommodation sectors in 2023?')]\n\n- Finance_aimessage:\ncontent='' additional_kwargs={'tool_calls': {'type': 'function', 'function': {'name': 'finance_service', 'arguments': {'startdate': '01-01-2023', 'enddate': '31-12-2023'}}}} response_metadata={'token_usage': {'generated_token_count': 393, 'input_token_count': 902}, 'model_name': 'mistralai/mixtral-8x7b-instruct-v01', 'system_fingerprint': '', 'finish_reason': 'stop_sequence'} id='run-f5865bca-48b5-49ba-b285-adb15235d79d-0' tool_calls=[{'name': 'finance_service', 'args': {'startdate': '01-01-2023', 'enddate': '31-12-2023'}, 'id': '1723450746.65', 'type': 'tool_call'}] usage_metadata={'input_tokens': 902, 'output_tokens': 393, 'total_tokens': 1295}\n\n- Finance_tools:\n[{'name': 'finance_service', 'args': {'startdate': '01-01-2023', 'enddate': '31-12-2023'}, 'id': '1723450746.65', 'type': 'tool_call'}]\n\n- Invoke example finance endpoint:\n Your finance request is from 01-01-2023 to 31-12-2023\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomassuedbroecker%2Ffunction_calling_langchain_watsonx_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomassuedbroecker%2Ffunction_calling_langchain_watsonx_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomassuedbroecker%2Ffunction_calling_langchain_watsonx_example/lists"}