forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
971 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
San Francisco Weather Report: | ||
|
||
Morning: 53°, Chance of Rain 1% | ||
Afternoon: 59°, Chance of Rain 0% | ||
Evening: 52°, Chance of Rain 3% | ||
Overnight: 48°, Chance of Rain 2% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { AutoGPT } from "langchain/experimental/autogpt"; | ||
import { ReadFileTool, WriteFileTool, SerpAPI } from "langchain/tools"; | ||
import { NodeFileStore } from "langchain/stores/file/node"; | ||
import { HNSWLib } from "langchain/vectorstores/hnswlib"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
import { ChatOpenAI } from "langchain/chat_models/openai"; | ||
|
||
const store = new NodeFileStore(); | ||
|
||
const tools = [ | ||
new ReadFileTool({ store }), | ||
new WriteFileTool({ store }), | ||
new SerpAPI(process.env.SERPAPI_API_KEY, { | ||
location: "San Francisco,California,United States", | ||
hl: "en", | ||
gl: "us", | ||
}), | ||
]; | ||
|
||
const vectorStore = new HNSWLib(new OpenAIEmbeddings(), { | ||
space: "cosine", | ||
numDimensions: 1536, | ||
}); | ||
|
||
const autogpt = AutoGPT.fromLLMAndTools( | ||
new ChatOpenAI({ temperature: 0 }), | ||
tools, | ||
{ | ||
memory: vectorStore.asRetriever(), | ||
aiName: "Tom", | ||
aiRole: "Assistant", | ||
} | ||
); | ||
|
||
await autogpt.run(["write a weather report for SF today"]); | ||
/* | ||
{ | ||
"thoughts": { | ||
"text": "I need to write a weather report for SF today. I should use a search engine to find the current weather conditions.", | ||
"reasoning": "I don't have the current weather information for SF in my short term memory, so I need to use a search engine to find it.", | ||
"plan": "- Use the search command to find the current weather conditions for SF\n- Write a weather report based on the information found", | ||
"criticism": "I need to make sure that the information I find is accurate and up-to-date.", | ||
"speak": "I will use the search command to find the current weather conditions for SF." | ||
}, | ||
"command": { | ||
"name": "search", | ||
"args": { | ||
"input": "current weather conditions San Francisco" | ||
} | ||
} | ||
} | ||
{ | ||
"thoughts": { | ||
"text": "I have found the current weather conditions for SF. I need to write a weather report based on this information.", | ||
"reasoning": "I have the information I need to write a weather report, so I should use the write_file command to save it to a file.", | ||
"plan": "- Use the write_file command to save the weather report to a file", | ||
"criticism": "I need to make sure that the weather report is clear and concise.", | ||
"speak": "I will use the write_file command to save the weather report to a file." | ||
}, | ||
"command": { | ||
"name": "write_file", | ||
"args": { | ||
"file_path": "weather_report.txt", | ||
"text": "San Francisco Weather Report:\n\nMorning: 53°, Chance of Rain 1%\nAfternoon: 59°, Chance of Rain 0%\nEvening: 52°, Chance of Rain 3%\nOvernight: 48°, Chance of Rain 2%" | ||
} | ||
} | ||
} | ||
{ | ||
"thoughts": { | ||
"text": "I have completed all my objectives. I will use the finish command to signal that I am done.", | ||
"reasoning": "I have completed the task of writing a weather report for SF today, so I don't need to do anything else.", | ||
"plan": "- Use the finish command to signal that I am done", | ||
"criticism": "I need to make sure that I have completed all my objectives before using the finish command.", | ||
"speak": "I will use the finish command to signal that I am done." | ||
}, | ||
"command": { | ||
"name": "finish", | ||
"args": { | ||
"response": "I have completed all my objectives." | ||
} | ||
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { AutoGPT } from "langchain/experimental/autogpt"; | ||
import { ReadFileTool, WriteFileTool, SerpAPI } from "langchain/tools"; | ||
import { InMemoryFileStore } from "langchain/stores/file/in_memory"; | ||
import { MemoryVectorStore } from "langchain/vectorstores/memory"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
import { ChatOpenAI } from "langchain/chat_models/openai"; | ||
|
||
const store = new InMemoryFileStore(); | ||
|
||
const tools = [ | ||
new ReadFileTool({ store }), | ||
new WriteFileTool({ store }), | ||
new SerpAPI(process.env.SERPAPI_API_KEY, { | ||
location: "San Francisco,California,United States", | ||
hl: "en", | ||
gl: "us", | ||
}), | ||
]; | ||
|
||
const vectorStore = new MemoryVectorStore(new OpenAIEmbeddings()); | ||
|
||
const autogpt = AutoGPT.fromLLMAndTools( | ||
new ChatOpenAI({ temperature: 0 }), | ||
tools, | ||
{ | ||
memory: vectorStore.asRetriever(), | ||
aiName: "Tom", | ||
aiRole: "Assistant", | ||
} | ||
); | ||
|
||
await autogpt.run(["write a weather report for SF today"]); | ||
/* | ||
{ | ||
"thoughts": { | ||
"text": "I need to write a weather report for SF today. I should use a search engine to find the current weather conditions.", | ||
"reasoning": "I don't have the current weather information for SF in my short term memory, so I need to use a search engine to find it.", | ||
"plan": "- Use the search command to find the current weather conditions for SF\n- Write a weather report based on the information found", | ||
"criticism": "I need to make sure that the information I find is accurate and up-to-date.", | ||
"speak": "I will use the search command to find the current weather conditions for SF." | ||
}, | ||
"command": { | ||
"name": "search", | ||
"args": { | ||
"input": "current weather conditions San Francisco" | ||
} | ||
} | ||
} | ||
{ | ||
"thoughts": { | ||
"text": "I have found the current weather conditions for SF. I need to write a weather report based on this information.", | ||
"reasoning": "I have the information I need to write a weather report, so I should use the write_file command to save it to a file.", | ||
"plan": "- Use the write_file command to save the weather report to a file", | ||
"criticism": "I need to make sure that the weather report is clear and concise.", | ||
"speak": "I will use the write_file command to save the weather report to a file." | ||
}, | ||
"command": { | ||
"name": "write_file", | ||
"args": { | ||
"file_path": "weather_report.txt", | ||
"text": "San Francisco Weather Report:\n\nMorning: 53°, Chance of Rain 1%\nAfternoon: 59°, Chance of Rain 0%\nEvening: 52°, Chance of Rain 3%\nOvernight: 48°, Chance of Rain 2%" | ||
} | ||
} | ||
} | ||
{ | ||
"thoughts": { | ||
"text": "I have completed all my objectives. I will use the finish command to signal that I am done.", | ||
"reasoning": "I have completed the task of writing a weather report for SF today, so I don't need to do anything else.", | ||
"plan": "- Use the finish command to signal that I am done", | ||
"criticism": "I need to make sure that I have completed all my objectives before using the finish command.", | ||
"speak": "I will use the finish command to signal that I am done." | ||
}, | ||
"command": { | ||
"name": "finish", | ||
"args": { | ||
"response": "I have completed all my objectives." | ||
} | ||
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.