{"id":19112551,"url":"https://github.com/mshumer/anthropic_with_functions","last_synced_at":"2025-08-22T08:31:17.341Z","repository":{"id":181277197,"uuid":"666511152","full_name":"mshumer/anthropic_with_functions","owner":"mshumer","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-17T03:30:37.000Z","size":16,"stargazers_count":194,"open_issues_count":2,"forks_count":21,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-13T10:25:25.321Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mshumer.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}},"created_at":"2023-07-14T17:55:23.000Z","updated_at":"2024-11-04T02:33:51.000Z","dependencies_parsed_at":"2023-07-14T19:35:46.232Z","dependency_job_id":null,"html_url":"https://github.com/mshumer/anthropic_with_functions","commit_stats":null,"previous_names":["mshumer/anthropic_with_functions"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshumer%2Fanthropic_with_functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshumer%2Fanthropic_with_functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshumer%2Fanthropic_with_functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshumer%2Fanthropic_with_functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mshumer","download_url":"https://codeload.github.com/mshumer/anthropic_with_functions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230575851,"owners_count":18247484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-09T04:33:28.421Z","updated_at":"2024-12-20T11:07:46.989Z","avatar_url":"https://github.com/mshumer.png","language":"Python","readme":"# Anthropic with Functions\n\nThis library allows you to use the Anthropic Claude models with OpenAI-like Functions.\n\nIt's super rough and early, so feel free to make improvements if you want!\n\n## Installation\n\nYou can install this package directly from GitHub:\n\n```bash\npip install git+https://github.com/mshumer/anthropic_with_functions.git\n```\n\n## Usage\n\nHere's a basic usage example:\n\n```python\nfrom anthropic_function import AnthropicFunction\nimport json\n\nanthropic_func = AnthropicFunction(api_key=\"ANTHROPIC_API_KEY\", model=\"claude-2\", temperature=0.7, max_tokens_to_sample=500)\n\n# Define your functions\ndef get_current_weather(location, unit=\"fahrenheit\"):\n  # Get the current weather in a given location\n  weather_info = {\n      \"location\": location,\n      \"temperature\": \"72\", # hardcoded for the example\n      \"unit\": unit,\n      \"forecast\": [\"sunny\", \"windy\"], # hardcoded for the example\n  }\n  return json.dumps(weather_info)\n\n# Add your functions to the AnthropicFunction instance\nanthropic_func.add_function(\n    \"get_current_weather\", \"Get the current weather in a given location\",\n    [\"location: string\", \"unit: 'celsius' | 'fahrenheit'\"])\n\n# Define the conversation messages\nmessages = [{\"role\": \"HUMAN\", \"content\": \"how are you today?\"}, {\"role\": \"AI\", \"content\": \"I'm good, thanks for asking!\"}, {\"role\": \"HUMAN\", \"content\": \"Remind me what I just asked you?\"}, {\"role\": \"AI\", \"content\": \"You just asked me, how are you today? and I responded, I'm good, thanks for asking!\"}, {\"role\": \"HUMAN\", \"content\": \"What's the weather in London?\"}]\n\n# Call the model (it will return either a function or a normal message)\nresponse = anthropic_func.call(messages, model=\"claude-2\", temperature=0.8, max_tokens_to_sample=400)\n\nif response[\"function\"]:\n  # Parse and then call the function with the arguments\n  function_output = None\n\n  # Depending on your function(s), write parsing code to grab the function name and arguments\n  #### PARSING CODE GOES HERE\n  function_name = 'get_current_weather' # placeholder -- replace with your parsing code that grabs the function name\n  function_arguments = {'location': 'london', 'unit': 'celsius'} # placeholder -- replace with your parsing code that grabs the function arguments\n\n  # Now, call the relevant function with the arguments, return the result as `function_output`\n  if function_name == 'get_current_weather':\n    function_output = get_current_weather(location=function_arguments['location'], unit=function_arguments['unit'])\n  # Describe the function's output\n  if function_output is not None:\n      response = anthropic_func.describe_function_output(function_name, function_arguments, function_output, messages)\n      print('Response:', response['response'])\n\nelse:\n  print('No function found')\n  print('Response:', response['response'])\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\nSome ideas:\n- create automatic function / arguments parsing code so that the user doesn't need to write it themselves\n- generally get the library to parity w/ OpenAI's Functions system\n\n## License\n\nThis project is licensed under the terms of the MIT license.\n","funding_links":[],"categories":["📦 Legacy \u0026 Inactive Projects"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmshumer%2Fanthropic_with_functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmshumer%2Fanthropic_with_functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmshumer%2Fanthropic_with_functions/lists"}