OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
genai
/
venv
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
09/17/2024 07:46:25 AM
rwxr-xr-x
📄
.gitignore
40 bytes
05/09/2024 06:59:35 AM
rw-r--r--
📁
bin
-
05/09/2024 07:00:17 AM
rwxr-xr-x
📁
lib
-
05/09/2024 06:59:35 AM
rwxr-xr-x
📄
process.py
3.11 KB
05/09/2024 06:09:07 AM
rw-rw-r--
📄
pyvenv.cfg
206 bytes
05/09/2024 06:59:35 AM
rw-r--r--
Editing: process.py
Close
# API key = sk-proj-FrlWqCTIyid7DZGorv0uT3BlbkFJzqrUB0km57kpp4aFPNV7 # Organisation id = org-pxYT08uLTCdYVPRmnn180ZwA # Project id = proj_aN6BosDXudraB7y2MGFw7tIq from openai import OpenAI import sys, json, datetime json_file = sys.argv[1] with open(json_file, 'r') as file: json_data = json.load(file) headline = json_data["headline"] objective = json_data["objective"] target_grp = json_data["target_grp"] keywords = json_data["keywords"] typeofarticle = json_data["typeofarticle"] no_of_keywords = json_data["no_of_words"] outline = json_data["outline"] primary_src = json_data["primary_src"] secondary_src = json_data["secondary_src"] def prompt(headline, objective, target_grp, keywords, typeofarticle, no_of_words, primary_source, secondary_source): if typeofarticle == "Press Release": prompt_message = f"You are an official Public Relational officer. You are issuing a press release for public consumption." else: prompt_message = f"You are a writer and you are writing an article." prompt_message += f"The headlines of the {typeofarticle} will be {headline}. The objective of the {typeofarticle} is {objective}. The {typeofarticle} is targeted to {target_grp}. The {typeofarticle} uses the following keywords: {keywords}." if typeofarticle == "Press Release": prompt_message +="give me the press release in json format where attributes are title, subtitle, date, location, body of the press release." else: prompt_message +="give me the article in json format where attributes are headline, subtitle, date, location, body of the article." prompt_message += f"Make sure that the size of the article should not exceed more than {no_of_words} words." prompt_message += f"Also refer the website{'s' if secondary_source else ''} mentioned: {primary_source}" + (f" and {secondary_source}" if secondary_source else "") return prompt_message from_address = "Author,\nKnobly Cream\n+91 12345 67890" def OpenAIGenerate(prompt, typeofarticle): client = OpenAI(api_key="sk-proj-FrlWqCTIyid7DZGorv0uT3BlbkFJzqrUB0km57kpp4aFPNV7") messages=[{"role": "system", "content": "You are a professional who is working for a famous newspaper company"}] if prompt: messages.append({"role":"user", "content":prompt}) if typeofarticle == "Press Release": messages.append({"role":"system", "content": "Do not mention any press release or immediate release and location. generate only the body of the press release"}) chat = client.chat.completions.create( model = "gpt-4", messages = messages ) reply= chat.choices[0].message.content messages.append({"role":"assistant","content":reply}) return reply prompt_message = prompt(headline, objective, target_grp, keywords, typeofarticle, no_of_keywords, primary_src, secondary_src) result = OpenAIGenerate(prompt_message, typeofarticle) data = {"prompt": result} with open('temp.json','w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=4) # print(prompt_message, "\n\n\n") print(result)