You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -174,6 +195,21 @@ from my_module import get_temperature
174
195
agent.register_function(get_temperature)
175
196
```
176
197
198
+
Alternatively, you can define a function descriptor manually and register it using the `register_descriptor` method. In this case, a `json_representation` compatible with [OpenAI function calling API](https://platform.openai.com/docs/api-reference/chat/create#chat/create-functions) should be provided.
199
+
200
+
```python
201
+
from agent_dingo.descriptor import FunctionDescriptor
_Note: the "usage" metric accumulates the number of tokens used for all intermediate function calls during the conversation._
385
+
386
+
### LangChain Tools 🦜️🔗
387
+
388
+
It is possible to convert [Langchain Tools](https://python.langchain.com/docs/modules/agents/tools/) into function descriptors in order to register them with Dingo. The converter can be used as follows:
389
+
390
+
1. Install langchain:
391
+
392
+
```bash
393
+
pip install agent_dingo[langchain]
394
+
```
395
+
396
+
2. Define the tool, we will use the Wikipedia tool as an example:
397
+
398
+
```python
399
+
from langchain.tools.wikipedia.tool import WikipediaQueryRun
400
+
from langchain.utilities.wikipedia import WikipediaAPIWrapper
Please refer to the [LangChain documentation](https://api.python.langchain.com/en/latest/api_reference.html#module-langchain.tools) for more details on how to define the tools.
405
+
406
+
3. Convert the tool into a function descriptor and register:
407
+
408
+
```python
409
+
from agent_dingo.langchain import convert_langchain_tool
410
+
descriptor = convert_langchain_tool(tool)
411
+
agent.register_descriptor(descriptor)
412
+
```
413
+
414
+
4. Run the conversation:
415
+
416
+
```python
417
+
# The agent will query Wikipedia to obtain the answer.
418
+
agent.chat("What is LangChain according to Wikipedia? Explain in one sentence.")
419
+
420
+
# > According to Wikipedia, LangChain is a framework designed to simplify the creation of applications using large language models (LLMs), with use-cases including document analysis and summarization, chatbots, and code analysis.
421
+
```
422
+
423
+
In comparison, when we try to query ChatGPT directly with the same question, we get the following hallucinated response (since it does not have access to the relevant up-to-date information):
424
+
425
+
```python
426
+
# > LangChain is a blockchain-based platform that aims to provide language learning services and connect language learners with native speakers for real-time practice and feedback.
427
+
```
428
+
429
+
_Note: some of the tools might be incompatible with (or simply unsuitable for) Dingo. We do not guarantee that all of the tools will work out of the box._
0 commit comments