Amazing-Python-Scripts

Форк
0
43 строки · 1.6 Кб
1
from langchain.llms import OpenAI
2
from langchain.prompts import PromptTemplate
3
from langchain.chains import LLMChain
4
from langchain.tools import DuckDuckGoSearchRun
5

6
# Function to generate video script
7

8

9
def generate_script(prompt, video_length, creativity, api_key):
10

11
    # Template for generating 'Title'
12
    title_template = PromptTemplate(
13
        input_variables=['subject'],
14
        template='Please come up with a title for a YouTube video on the  {subject}.'
15
    )
16

17
    # Template for generating 'Video Script' using search engine
18
    script_template = PromptTemplate(
19
        input_variables=['title', 'DuckDuckGo_Search', 'duration'],
20
        template='Create a script for a YouTube video based on this title for me. TITLE: {title} of duration: {duration} minutes using this search data {DuckDuckGo_Search} '
21
    )
22

23
    # Setting up OpenAI LLM
24
    llm = OpenAI(temperature=creativity, openai_api_key=api_key,
25
                 model_name='gpt-3.5-turbo')
26

27
    # Creating chain for 'Title' & 'Video Script'
28
    title_chain = LLMChain(llm=llm, prompt=title_template, verbose=True)
29
    script_chain = LLMChain(llm=llm, prompt=script_template, verbose=True)
30

31
    # https://python.langchain.com/docs/modules/agents/tools/integrations/ddg
32
    search = DuckDuckGoSearchRun()
33

34
    # Executing the chains we created for 'Title'
35
    title = title_chain.run(prompt)
36

37
    # Executing the chains we created for 'Video Script' by taking help of search engine 'DuckDuckGo'
38
    search_result = search.run(prompt)
39
    script = script_chain.run(
40
        title=title, DuckDuckGo_Search=search_result, duration=video_length)
41

42
    # Returning the output
43
    return search_result, title, script
44

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.