Skip to content

Commit

Permalink
docs: Simplified Prompts sample app.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 12, 2024
1 parent 40f8bdb commit 8047309
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions examples/LangChain.Samples.Prompts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
using LangChain.Providers.OpenAI.Predefined;
using LangChain.Schema;

const string apiKey = "API-KEY";
using var httpClient = new HttpClient();
var llm = new OpenAiLatestFastChatModel(apiKey);
var llm = new OpenAiLatestFastChatModel(Environment.GetEnvironmentVariable("OPENAI_API_KEY")!);

var template = "What is a good name for a company that makes {product}?";
var prompt = new PromptTemplate(new PromptTemplateInput(template, new List<string>(1) { "product" }));
var prompt = new PromptTemplate(new PromptTemplateInput(
template: "What is a good name for a company that makes {product}?",
inputVariables: ["product"]));

var chain = new LlmChain(new LlmChainInput(llm, prompt));

var result = await chain.CallAsync(new ChainValues(new Dictionary<string, object>(1)
var result = await chain.CallAsync(new ChainValues(new Dictionary<string, object>
{
{ "product", "colourful socks" }
}));
Expand All @@ -26,16 +25,13 @@

Console.WriteLine(result2);

// We can also construct an LLMChain from a ChatPromptTemplate and a chat model.
var chat = new OpenAiLatestFastChatModel(apiKey);

var chatPrompt = ChatPromptTemplate.FromPromptMessages(new List<BaseMessagePromptTemplate>(2)
{
SystemMessagePromptTemplate.FromTemplate("You are a helpful assistant that translates {input_language} to {output_language}."),
var chatPrompt = ChatPromptTemplate.FromPromptMessages([
SystemMessagePromptTemplate.FromTemplate(
"You are a helpful assistant that translates {input_language} to {output_language}."),
HumanMessagePromptTemplate.FromTemplate("{text}")
});
]);

var chainB = new LlmChain(new LlmChainInput(chat, chatPrompt)
var chainB = new LlmChain(new LlmChainInput(llm, chatPrompt)
{
Verbose = true
});
Expand Down

0 comments on commit 8047309

Please sign in to comment.