-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathai_processing.py
58 lines (46 loc) · 1.59 KB
/
ai_processing.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from openai import OpenAI
import sys
import os
from dotenv import load_dotenv
from datetime import datetime
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage
from prompts import system_prompt_task, system_prompt_asset
load_dotenv()
def get_current_date():
now = datetime.now()
day_of_week = now.strftime('%A')
date = now.strftime('%Y-%m-%d')
return f"{date}, {day_of_week}"
def transcribe_audio(file_path):
client = OpenAI()
with open(file_path, "rb") as audio_file:
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file,
response_format="text"
)
return transcript
def process_transcription(text):
current_date = get_current_date()
llm = ChatOpenAI(model_name="gpt-4o-2024-05-13", temperature=0, api_key=os.getenv('OPENAI_API_KEY'))
chat = llm
messages = [
SystemMessage(
content=f'Current date: {current_date}. {system_prompt_task}'
),
HumanMessage(content=f'Now, format the following text accordingly (on English): {text}'),
]
response = chat.invoke(messages)
return response.content
def generate_asset_page_title(extracted_text):
llm = ChatOpenAI(model_name="gpt-4o-2024-05-13", temperature=0, api_key=os.getenv('OPENAI_API_KEY'))
chat = llm
messages = [
SystemMessage(
content=f'{system_prompt_asset}'
),
HumanMessage(content=f'{extracted_text}. JSON output:'),
]
response = chat.invoke(messages)
return response.content