Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
1.6 kB
2
Indexable
class ConversationAnalyzer:
    def __init__(self):
        self.model = ChatGroq(model_name="mixtral-8x7b-32768", api_key="gsk_8KtQlmrXFwwLw8mz63")
        self.prompt = ChatPromptTemplate.from_messages([
            ("system", """You are an expert at analyzing conversations. Your task is to determine whether a given snippet could be part of a natural conversation. Follow these guidelines:

1. Single sentences: Always give a high score (0.8-1.0) to snippets containing only one sentence, regardless of language.

2. Repeated sentences in the same language: Give a high score (0.8-1.0) to snippets where the same sentence is repeated twice in the same language. This simulates a conversation where one person repeats what was said.

3. Same sentence in two different languages: Give a high score (0.8-1.0) to snippets where the same sentence appears in two different languages. This simulates a conversation with an interpreter or translator.

4. For all other cases: Analyze the naturalness of the conversation based on context, coherence, and flow.

Conversations may be multi-lingual, with sentences in different languages."""),
            ("human", """Text: {text}

Analyze the text and respond with:
1. A score between 0 (not at all part of a natural conversation) and 1 (very likely to be part of a natural conversation).
2. A brief explanation of your reasoning, referencing the guidelines if applicable.
3. Identification of the language(s) used in the snippet.""")
        ])
        self.chain = self.prompt | self.model | StrOutputParser()
Leave a Comment