File size: 1,451 Bytes
4df03b2
 
 
 
674cf04
4df03b2
 
674cf04
4df03b2
d17cf2d
cb05dff
4df03b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from openai import OpenAI
import streamlit as st
from groq_response import groq_response
import os

    

client = OpenAI(api_key=os.getenv('OPENAI_API'))
prompt = st.chat_input("Type your question...")
my_assistant = client.beta.assistants.retrieve("asst_ucgc8lzekHeOFrvjaKzcJOmD")
ass_id = "asst_ucgc8lzekHeOFrvjaKzcJOmD"

def retrival_openai(prompt, instructions):
    thread = client.beta.threads.create()
    message = client.beta.threads.messages.create(
        thread_id=thread.id,
        role="user",
        content=prompt
    )
    run = client.beta.threads.runs.create_and_poll(
        thread_id=thread.id,
        assistant_id=ass_id,
        instructions=instructions
    )
    if run.status == 'completed': 
        messages = client.beta.threads.messages.list(
            thread_id=thread.id
        )
        assistant_messages = [message for message in messages.data if message.role == 'assistant']
        for message in assistant_messages:
            for content_block in message.content:
                # Check if there's a method or property to get 'value'
                if hasattr(content_block.text, 'value'):
                    return content_block.text.value                    
                else:
                    # Otherwise print the object to debug
                    #st.write(messages)
                    #st.write(content_block.text)
                    return None
    else:
        return None