Adjust prompt, improvements
This commit is contained in:
parent
30654c1580
commit
44902513fd
29
main.py
29
main.py
|
@ -21,20 +21,21 @@ TIMEZONE_CALGARY = pytz.timezone('America/Edmonton')
|
|||
bot = TelegramClient('data/bot', secrets.API_ID, secrets.API_HASH).start(bot_token=secrets.API_TOKEN)
|
||||
|
||||
CHATGPT_TEMPLATE = '''
|
||||
Turn this forum post into an two paragraph instagram caption that tells about what a member of our makerspace has made.
|
||||
Turn this forum post into an two paragraph summary that tells about what a member of our makerspace has made.
|
||||
Add the hashtags: #makerspace #yyc #maker #diy #calgary and several relevant to the post at the end.
|
||||
Include a sentence explaining that this was made at Calgary Protospace, a makerspace that's non-profit and volunteer run.
|
||||
Only say the member's name once.
|
||||
Use no more than 1000 characters.
|
||||
Include one sentence explaining that this was made at Calgary Protospace, a makerspace that's non-profit and volunteer run.
|
||||
Only mention the member's name once.
|
||||
Keep it short, use no more than 1000 characters.
|
||||
Write in third person.
|
||||
Do not @ tag anybody.
|
||||
Use neutral sounding phrases.
|
||||
|
||||
Title: {}
|
||||
Member: {}
|
||||
Post Body:
|
||||
```
|
||||
{}
|
||||
```'''
|
||||
```
|
||||
'''
|
||||
|
||||
try:
|
||||
data = json.load(open('data/data.json'))
|
||||
|
@ -116,8 +117,8 @@ def api_chatgpt(prompt):
|
|||
|
||||
data = dict(
|
||||
messages=thread,
|
||||
model='gpt-4-1106-preview',
|
||||
temperature=0.5,
|
||||
model='gpt-3.5-turbo', #'gpt-4-1106-preview',
|
||||
temperature=0.8,
|
||||
user='protogram',
|
||||
max_tokens=1000,
|
||||
)
|
||||
|
@ -153,7 +154,7 @@ def get_portal_name_from_discourse(username):
|
|||
logging.error('Problem with getting member name: {} - {}'.format(e.__class__.__name__, str(e)))
|
||||
return False
|
||||
|
||||
def generate_caption(topic):
|
||||
def generate_caption(topic, prev_captions='N/A'):
|
||||
title = topic['title']
|
||||
|
||||
username = topic['post_stream']['posts'][0]['username']
|
||||
|
@ -169,6 +170,7 @@ def generate_caption(topic):
|
|||
filtered_lines = [line for line in lines if 'KB' not in line and 'MB' not in line]
|
||||
body = '\n'.join(filtered_lines).replace('\n\n\n', '\n\n')
|
||||
|
||||
#prompt = CHATGPT_TEMPLATE.format(title, member, body, prev_captions)
|
||||
prompt = CHATGPT_TEMPLATE.format(title, member, body)
|
||||
|
||||
logging.info('Generating caption for: {}\n{}'.format(title, body))
|
||||
|
@ -265,6 +267,13 @@ async def process_topics():
|
|||
|
||||
logging.info('Next valid topic ID: {}'.format(topic_id))
|
||||
|
||||
try:
|
||||
prev_states = list(data['states'].values())[-5:]
|
||||
prev_captions = '\n\n'.join([x['caption'] for x in prev_states])
|
||||
except:
|
||||
prev_captions = 'N/A'
|
||||
logging.info('Previous captions:\n{}\n\n'.format(prev_captions))
|
||||
|
||||
if topic_id not in data['states']:
|
||||
data['states'][topic_id] = dict(
|
||||
status='NEW',
|
||||
|
@ -282,7 +291,7 @@ async def process_topics():
|
|||
store_data()
|
||||
continue
|
||||
|
||||
caption = generate_caption(topic)
|
||||
caption = generate_caption(topic, prev_captions)
|
||||
state['caption'] = caption
|
||||
|
||||
result = await send_data_to_admin(state)
|
||||
|
|
Loading…
Reference in New Issue
Block a user