Skip to content

Commit

Permalink
Make OpenAI function chain docs more readable (langchain-ai#1902)
Browse files Browse the repository at this point in the history
* Fix docs and Google Vertex integration test

* Update functions docs style

* Make OpenAI function chain docs more readable
  • Loading branch information
jacoblee93 authored Jul 9, 2023
1 parent 3635d96 commit 5a2a361
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
22 changes: 12 additions & 10 deletions examples/src/chains/openai_functions_extraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { z } from "zod";
import { ChatOpenAI } from "langchain/chat_models/openai";
import { createExtractionChainFromZod } from "langchain/chains";

const chain = createExtractionChainFromZod(
z.object({
"person-name": z.string().optional(),
"person-age": z.number().optional(),
"person-hair_color": z.string().optional(),
"dog-name": z.string().optional(),
"dog-breed": z.string().optional(),
}),
new ChatOpenAI({ modelName: "gpt-3.5-turbo-0613", temperature: 0 })
);
const zodSchema = z.object({
"person-name": z.string().optional(),
"person-age": z.number().optional(),
"person-hair_color": z.string().optional(),
"dog-name": z.string().optional(),
"dog-breed": z.string().optional(),
});
const chatModel = new ChatOpenAI({
modelName: "gpt-3.5-turbo-0613",
temperature: 0,
});
const chain = createExtractionChainFromZod(zodSchema, chatModel);

console.log(
await chain.run(`Alex is 5 feet tall. Claudia is 4 feet taller Alex and jumps higher than him. Claudia is a brunette and Alex is blonde.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { createOpenAPIChain } from "langchain/chains";
import { ChatOpenAI } from "langchain/chat_models/openai";

const chatModel = new ChatOpenAI({ modelName: "gpt-4-0613", temperature: 0 });

const chain = await createOpenAPIChain("https://api.speak.com/openapi.yaml", {
llm: new ChatOpenAI({ modelName: "gpt-4-0613", temperature: 0 }),
llm: chatModel,
headers: {
authorization: "Bearer SOME_TOKEN",
},
Expand Down
24 changes: 13 additions & 11 deletions examples/src/chains/openai_functions_tagging.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { createTaggingChain } from "langchain/chains";
import { ChatOpenAI } from "langchain/chat_models/openai";
import type { FunctionParameters } from "langchain/output_parsers";

const chain = createTaggingChain(
{
type: "object",
properties: {
sentiment: { type: "string" },
tone: { type: "string" },
language: { type: "string" },
},
required: ["tone"],
const schema: FunctionParameters = {
type: "object",
properties: {
sentiment: { type: "string" },
tone: { type: "string" },
language: { type: "string" },
},
new ChatOpenAI({ modelName: "gpt-4-0613", temperature: 0 })
);
required: ["tone"],
};

const chatModel = new ChatOpenAI({ modelName: "gpt-4-0613", temperature: 0 });

const chain = createTaggingChain(schema, chatModel);

console.log(
await chain.run(
Expand Down
1 change: 1 addition & 0 deletions langchain/src/output_parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export { CombiningOutputParser } from "./combining.js";
export { RouterOutputParser, RouterOutputParserInput } from "./router.js";
export { CustomListOutputParser } from "./list.js";
export {
FunctionParameters,
OutputFunctionsParser,
JsonOutputFunctionsParser,
JsonKeyOutputFunctionsParser,
Expand Down

0 comments on commit 5a2a361

Please sign in to comment.