forked from apradoada/NPC-Generator
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution with gemini #2
Open
apradoada
wants to merge
10
commits into
solution
Choose a base branch
from
solution-with-gemini
base: solution
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
232e416
Removed solution from master branch
apradoada 4c9b012
removed OpenAI library from imports
apradoada df2f4ed
Remove OpenAI References
apradoada bc81ef4
remove
apradoada 4ef1e88
added generate_greetings function header
apradoada e59eefa
Solution created using Gemini
apradoada b382021
Changed variable names and added comments
apradoada 2592fbd
Remove jsonify and make_response where possible
kelsey-steven-ada cb4eb89
Small changes to typo & casing in prompt to match lesson
kelsey-steven-ada 68bc123
Merge pull request #4 from AdaGold/ks_update_solution_return_values
kelsey-steven-ada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,10 +3,13 @@ | |||||
from ..models.character import Character | ||||||
from ..models.greeting import Greeting | ||||||
from sqlalchemy import func, union, except_ | ||||||
from openai import OpenAI | ||||||
|
||||||
import google.generativeai as genai | ||||||
import os | ||||||
|
||||||
genai.configure(api_key=os.environ.get("GEMINI_API_KEY")) | ||||||
|
||||||
bp = Blueprint("characters", __name__, url_prefix="/characters") | ||||||
client = OpenAI() | ||||||
|
||||||
@bp.post("") | ||||||
def create_character(): | ||||||
|
@@ -30,15 +33,7 @@ def get_characters(): | |||||
response = [] | ||||||
|
||||||
for character in characters: | ||||||
response.append( | ||||||
{ | ||||||
"id" : character.id, | ||||||
"name" : character.name, | ||||||
"personality" : character.personality, | ||||||
"occupation" : character.occupation, | ||||||
"age" : character.age | ||||||
} | ||||||
) | ||||||
response.append(character.to_dict()) | ||||||
|
||||||
return jsonify(response) | ||||||
|
||||||
|
@@ -58,21 +53,20 @@ def get_greetings(char_id): | |||||
|
||||||
return jsonify(response) | ||||||
|
||||||
|
||||||
@bp.post("/<char_id>/generate") | ||||||
def add_greetings(char_id): | ||||||
character_obj = validate_model(Character, char_id) | ||||||
greetings = generate_greetings(character_obj) | ||||||
print(greetings) | ||||||
|
||||||
if character_obj.greetings: | ||||||
return make_response(jsonify(f"Greetings already generated for {character_obj.name} "), 201) | ||||||
|
||||||
new_greetings = [] | ||||||
|
||||||
for greeting in greetings: | ||||||
text = greeting[greeting.find(" ")+1:] | ||||||
new_greeting = Greeting( | ||||||
greeting_text = text.strip("\""), | ||||||
greeting_text = greeting.strip("\""), #Removes quotes from each string | ||||||
character = character_obj | ||||||
) | ||||||
new_greetings.append(new_greeting) | ||||||
|
@@ -83,15 +77,12 @@ def add_greetings(char_id): | |||||
return make_response(jsonify(f"Greetings successfully added to {character_obj.name}"), 201) | ||||||
|
||||||
def generate_greetings(character): | ||||||
model = genai.GenerativeModel("gemini-1.5-flash") | ||||||
input_message = f"I am writing a rantasy RPG video game. I have an npc named {character.name} who is {character.age} years old. They are a {character.occupation} who has a {character.personality} personality. Please generate a python style list of 10 stock phrases they might use when the main character talks to them. Please Return just the list without a variable name and square brackets." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
response = model.generate_content(input_message) | ||||||
response_split = response.text.split("\n") #Splits response into a list of stock phrases, ends up with an empty string at index -1 | ||||||
return response_split[:-1] #Returns the stock phrases list, just without the empty string at the end | ||||||
|
||||||
input_message = f"I am writing a video game in the style of The Witcher. I have an npc named {character.name} who is {character.age} years old. They are a {character.occupation} who has a {character.personality} personality. Please generate a python style list of 10 stock phrases they might use when the main character talks to them" | ||||||
completion = client.chat.completions.create( | ||||||
model="gpt-3.5-turbo", | ||||||
messages=[ | ||||||
{"role": "user", "content": input_message} | ||||||
] | ||||||
) | ||||||
return(completion.choices[0].message.content.split("\n")) | ||||||
|
||||||
def validate_model(cls,id): | ||||||
try: | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from app import create_app, db | ||
|
||
|
||
my_app = create_app() | ||
with my_app.app_context(): | ||
db.session.clear() | ||
print("Session cleared.") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could remove
jsonify
through the project