Skip to content

Commit

Permalink
📚 add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketmaurya committed May 9, 2024
1 parent 89651f4 commit dc5082a
Showing 1 changed file with 101 additions and 9 deletions.
110 changes: 101 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

Build Agentic workflows with function calling, powered by LangChain.

## Installation

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/aniketmaurya/python-project-template?template=false)

## Installation

**Install latest branch:**

```shell
Expand All @@ -22,6 +22,8 @@ pip install git+https://github.com/aniketmaurya/agents.git@main

## Usage/Examples

### Simple tool use with a local or cloud LLM

LLM with access to weather API:

```python
Expand Down Expand Up @@ -73,23 +75,113 @@ print(tool_results)

</details>

You can also use Cohere's API for tool use/function calling:

```python
from agents.tools import get_current_weather

from agents.llms._cohere import CohereChatCompletion
from agents.tool_executor import need_tool_use

llm = CohereChatCompletion()
llm.bind_tools([get_current_weather])

messages = [
{
"role": "system",
"content": "You are a helpful assistant that has access to tools. Use the tools only if you don't have answers."
},
{"role": "user", "content": "how is the weather in London today?"}
]

output = llm.chat_completion(messages)

if need_tool_use(output):
tool_results = llm.run_tool(output)
tool_results[0]["role"] = "assistant"

updated_messages = messages + tool_results
updated_messages = updated_messages + [{"role": "system", "content": "Do not use any tools now."},
{"role": "user",
"content": "Think step by step and answer my question based on the above context."}
]
output = llm.chat_completion(updated_messages)

<!-- ## Demo
print(output.choices[0].message.content)
```

Insert gif or link to demo -->
<details>
<summary>See output:</summary>

The weather in London, as of 1:58 PM, is partly cloudy with a temperature of 20 degrees Celsius or
68 degrees
Fahrenheit. The humidity is at 49%, and the UV index is 5. There is no precipitation, and the wind
speed is mild at
7 km/h or 4 mph. The pressure is at 1029 millibars, with a visibility range of [
1;36m10 km or 6 miles. So, overall, it's
a pleasant day with mild temperatures and partly cloudy skies.

<!-- ## FAQ
</details>

#### Question 1
### Multi-modal Agent 👁🤖️

Answer 1
You can build an AI Agent that can see the world with computer vision.

#### Question 2
```python
from agents.llms.llm import LlamaCppChatCompletion
from agents.tools import get_current_weather, wikipedia_search, google_search, image_inspector

llm = LlamaCppChatCompletion.from_default_llm(n_ctx=0)
llm.bind_tools([google_search, wikipedia_search, image_inspector])

Answer 2 -->
image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
messages = [
{"role": "system", "content": "You are a helpful assistant that has access to tools and use that to help humans."},
{"role": "user",
"content": f"Check this image {image_url} and suggest me a location where I can go in London which looks similar"}
]
output = llm.chat_completion(messages)
tool_results = llm.run_tool(output)

updated_messages = messages + tool_results
messages = updated_messages + [{"role": "user", "content": "please answer me, based on the tool results."}]
output = llm.chat_completion(messages)
print(output.choices[0].message.content)
```

<details>
<summary>See output:</summary>

Based on the image you provided, it appears to be a nature boardwalk surrounded by lush green grass and a peaceful
sky filled with clouds. The presence of people indicates that it could be a popular spot for outdoor activities or
leisurely walks. If you're looking for a similar location in London, you might consider visiting one of the city's
many parks or nature reserves. Here are a few suggestions:

1. **Richmond Park**: This is the largest royal park in London and offers a variety of landscapes, including
open
grasslands, wooded areas, and lakes. It's a great place for walking, cycling, and enjoying the outdoors.

2. **Hampstead Heath**: Another large green space in London, Hampstead Heath is known for its ponds, meadows,
and
woodlands. It's a popular spot for picnics, sunbathing, and hiking.

3. **Greenwich Park**: This park offers panoramic views of the city and is home to several historic
buildings,
including the Royal Observatory. It's a great place for a leisurely walk or a picnic.

4. **Victoria Park**: A smaller but still beautiful park in East London, Victoria Park is known for its
lakes,
gardens, and outdoor events.

5. **Hyde Park**: One of the most central parks in London, Hyde Park offers a variety of attractions,
including the
Serpentine Lake, Speaker's Corner, and several monuments.

These locations all offer a peaceful and natural environment similar to the image you provided, making them
excellent choices for a day out in London.


</details>

## Acknowledgements

Expand Down

0 comments on commit dc5082a

Please sign in to comment.