-
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
1 parent
b8235b3
commit e95a261
Showing
23 changed files
with
2,878 additions
and
406 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,51 @@ | ||
"use server"; | ||
import { OpenAI } from "@langchain/openai"; | ||
import { RunnableSequence } from "@langchain/core/runnables"; | ||
import { StructuredOutputParser } from "langchain/output_parsers"; | ||
import { PromptTemplate } from "@langchain/core/prompts"; | ||
|
||
export const createCourse = async ({ | ||
unit, | ||
title, | ||
}: { | ||
unit: string; | ||
title: string; | ||
}) => { | ||
try { | ||
const parser = StructuredOutputParser.fromNamesAndDescriptions({ | ||
chapter_title: "one chapter in the unit", | ||
youtube_search_query: | ||
"best youtube query for the chapter_title so he can confirm his concepts", | ||
}); | ||
|
||
const chain = RunnableSequence.from([ | ||
PromptTemplate.fromTemplate( | ||
"Answer the users question as best as possible.\n{format_instructions}\n{question}" | ||
), | ||
new OpenAI({ temperature: 0 }), | ||
parser, | ||
]); | ||
|
||
const request1 = chain.invoke({ | ||
question: `The title of course is ${title}, It has a unit named ${unit}. I want to create a chapter which tell about the basics of the unit , so name chapter accordingly`, | ||
format_instructions: parser.getFormatInstructions(), | ||
}); | ||
|
||
const request2 = chain.invoke({ | ||
question: `The title of course is ${title}, It has a unit named ${unit}. I want to create a chapter which tell about the intermediate stuff of the unit , so name chapter accordingly`, | ||
format_instructions: parser.getFormatInstructions(), | ||
}); | ||
|
||
const request3 = chain.invoke({ | ||
question: `The title of course is ${title}, It has a unit named ${unit}. I want to create a chapter which tell about the advance stuff of the unit , so name chapter accordingly`, | ||
format_instructions: parser.getFormatInstructions(), | ||
}); | ||
|
||
const courses = await Promise.all([request1, request2, request3]); | ||
|
||
return { success: "success", courses: courses }; | ||
} catch (error) { | ||
console.log(error); | ||
return { error: error }; | ||
} | ||
}; |
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,32 @@ | ||
"use server"; | ||
import { RunnableSequence } from "@langchain/core/runnables"; | ||
import { StructuredOutputParser } from "langchain/output_parsers"; | ||
import { PromptTemplate } from "@langchain/core/prompts"; | ||
import { OpenAI } from "@langchain/openai"; | ||
|
||
export const createImageQuery = async ({ title }: { title: string }) => { | ||
try { | ||
const parser = StructuredOutputParser.fromNamesAndDescriptions({ | ||
image_url: | ||
"image url which suited my title and i can search it on unsplash", | ||
}); | ||
|
||
const chain = RunnableSequence.from([ | ||
PromptTemplate.fromTemplate( | ||
"Answer the users question as best as possible.\n{format_instructions}\n{question}" | ||
), | ||
new OpenAI({ temperature: 0 }), | ||
parser, | ||
]); | ||
|
||
const request = await chain.invoke({ | ||
question: `create image for the titlr : ${title}`, | ||
format_instructions: parser.getFormatInstructions(), | ||
}); | ||
|
||
return { success: "success", image: request }; | ||
} catch (error) { | ||
console.log(error); | ||
return { error: error }; | ||
} | ||
}; |
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,59 @@ | ||
"use server"; | ||
import { RunnableSequence } from "@langchain/core/runnables"; | ||
import { StructuredOutputParser } from "langchain/output_parsers"; | ||
import { PromptTemplate } from "@langchain/core/prompts"; | ||
import { OpenAI } from "@langchain/openai"; | ||
|
||
export const createQuestion = async ({ | ||
transcript, | ||
segment, | ||
}: { | ||
transcript: string; | ||
segment: "first" | "second" | "third" | "fourth"; | ||
}) => { | ||
try { | ||
const parser = StructuredOutputParser.fromNamesAndDescriptions({ | ||
question: | ||
"relevant question for this chapter , create 4 option , out of which one is corrct and all other is wrong and put those into below keys ", | ||
answer: "1st option , and this is right answer", | ||
option1: "2nd option , and this option is wrong", | ||
option2: "3rd option , and this option is wrong", | ||
option3: "4th option , and this option is wrong", | ||
}); | ||
|
||
const segmentLength = Math.floor(transcript.length / 4); | ||
let segmentText = ""; | ||
switch (segment) { | ||
case "first": | ||
segmentText = transcript.slice(0, segmentLength); | ||
break; | ||
case "second": | ||
segmentText = transcript.slice(segmentLength, 2 * segmentLength); | ||
break; | ||
case "third": | ||
segmentText = transcript.slice(2 * segmentLength, 3 * segmentLength); | ||
break; | ||
case "fourth": | ||
segmentText = transcript.slice(3 * segmentLength); | ||
break; | ||
} | ||
|
||
const chain = RunnableSequence.from([ | ||
PromptTemplate.fromTemplate( | ||
"Answer the users question as best as possible.\n{format_instructions}\n{question}" | ||
), | ||
new OpenAI({ temperature: 0, modelName: "gpt-3.5-turbo-1106" }), | ||
parser, | ||
]); | ||
|
||
const request = await chain.invoke({ | ||
question: `Create a question and answer object with 4 options out of which one is correct. The topic is based on the following content segment: ${segmentText}`, | ||
format_instructions: parser.getFormatInstructions(), | ||
}); | ||
|
||
return { success: "success", questions: request }; | ||
} catch (error) { | ||
console.log(error); | ||
return { error: error }; | ||
} | ||
}; |
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,33 @@ | ||
"use server"; | ||
import { RunnableSequence } from "@langchain/core/runnables"; | ||
import { StructuredOutputParser } from "langchain/output_parsers"; | ||
import { PromptTemplate } from "@langchain/core/prompts"; | ||
import { OpenAI } from "@langchain/openai"; | ||
|
||
export const createSummary = async ({ transcript }: { transcript: string }) => { | ||
try { | ||
const parser = StructuredOutputParser.fromNamesAndDescriptions({ | ||
summary: "a crisp summary of transcript that i will provide", | ||
}); | ||
|
||
const chain = RunnableSequence.from([ | ||
PromptTemplate.fromTemplate( | ||
"Answer the users question as best as possible.\n{format_instructions}\n{question}" | ||
), | ||
new OpenAI({ temperature: 0, modelName: "gpt-3.5-turbo-1106" }), | ||
parser, | ||
]); | ||
|
||
const request = await chain.invoke({ | ||
question: `Create summary of youtube transcript in less than 300 words. Do not talk of sponsor or anything unrealted to main topic , also do not introduce what the summary is about.\n${transcript}`, | ||
format_instructions: parser.getFormatInstructions(), | ||
}); | ||
|
||
console.log(request); | ||
|
||
return { success: "success", summary: request }; | ||
} catch (error) { | ||
console.log(error); | ||
return { error: error }; | ||
} | ||
}; |
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.