File size: 1,292 Bytes
7ad19af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from langchain.chat_models import ChatOpenAI
import streamlit as st
def chatseo():

    from langchain import PromptTemplate
    from langchain.prompts.chat import (
        ChatPromptTemplate,
        SystemMessagePromptTemplate,
        AIMessagePromptTemplate,
        HumanMessagePromptTemplate,
    )

    template="You are an SEO Analyser.\nYou will be given an issue dealt with SEO, and its description.\nFor a given url, you need to create a 5 step plan to fix that issue.\nRemember to give examples as well for each step. Include some necessary code to fix that issue like ```some code```."
    system_message_prompt = SystemMessagePromptTemplate.from_template(template)
    human_template="Issue: {issue}\nDescription: {description}\nURL: {url}"
    human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)

    chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
    return chat_prompt

# get a chat completion from the formatted messages
chat_prompt = chatseo()
def chat_with_chatseo(issue, description, url, chat_prompt = chat_prompt):
        chat = ChatOpenAI(openai_api_key=st.secrets["openai_api_key"])
        return chat(chat_prompt.format_prompt(issue=issue, description=description, url=url).to_messages())