Skip to content

Commit

Permalink
Merge pull request #288 from splashcat-ink/openai-groups-creating
Browse files Browse the repository at this point in the history
Openai groups creating
  • Loading branch information
catgirlinspace authored Jul 16, 2024
2 parents 322650a + a58517d commit e7cee67
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .idea/splashcat.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions assistant/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import transaction

from battles.models import Battle, BattleGroup
from users.models import User


def create_battle_group(user: User, params: dict) -> int:
battles = params.get('battles', [])
with transaction.atomic():
battles = Battle.objects.filter(pk__in=battles, uploader=user)
group = BattleGroup(creator=user)
group.save()

group.battles.add(*battles)

group.save()

return group.id
22 changes: 21 additions & 1 deletion assistant/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Create your views here.
import json

import django_htmx.http
from django.conf import settings
Expand All @@ -10,7 +11,7 @@
from django.views.decorators.http import require_POST
from openai import OpenAI

from assistant import orchestrator
from assistant import orchestrator, functions
from assistant.forms import CreateThreadForm
from assistant.models import Thread, SharedThread
from battles.models import Battle, BattleGroup
Expand Down Expand Up @@ -117,6 +118,25 @@ def get_thread_messages(request, thread_id):
latest_run = latest_run.data[0] if len(latest_run.data) > 0 else None
latest_status = latest_run.status if latest_run else 'completed'

if latest_status == 'requires_action' and latest_run.required_action:
# need to call functions
outputs = []

required_action = latest_run.required_action
tools = required_action.submit_tool_outputs.tool_calls
for tool in tools:
function_name = tool.function.name
python_function = getattr(functions, function_name)
if python_function:
result = python_function(thread.creator, params=json.loads(tool.function.arguments))
outputs.append({
'tool_call_id': tool.id,
'output': str(result),
})

latest_run = client.beta.threads.runs.submit_tool_outputs(thread_id=openai_thread_id, run_id=latest_run.id,
tool_outputs=outputs)

is_currently_done = latest_status in ['completed', 'expired', 'cancelled',
'failed'] and thread.status != thread.Status.PENDING

Expand Down
2 changes: 1 addition & 1 deletion battles/templates/battles/groups/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% block opengraph_head %}
<meta property="og:title" content="{{ battle_group.creator.display_name }}'s Shared Battle Group">

<meta property="og:description" content="Splashcat records battle data for later analysis.">
<meta property="og:description" content="Splashcat is an award-winning service that records battle data for later analysis.">

<meta name="twitter:card" content="summary_large_image">
<meta property="og:image"
Expand Down
2 changes: 1 addition & 1 deletion battles/templates/battles/view_battle.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<meta property="og:description" content="{% if battle.gpt_description_generated %}
{{ battle.gpt_description }}
{% else %}
Splashcat records battle data for later analysis.
Splashcat is an award-winning service that records battle data for later analysis.
{% endif %}">

<meta name="twitter:card" content="summary_large_image">
Expand Down
2 changes: 1 addition & 1 deletion battles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def view_battle_group(request, group_id):
'win_count': win_count,
'lose_count': lose_count,
'win_rate': win_rate,
'battles': battle_group.battles.order_by('-played_time'),
'battles': battle_group.battles.with_prefetch().order_by('-played_time'),
})


Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ eventlet = "^0.36.1"
django-unicorn = "^0.60.0"
psycopg = { extras = ["binary"], version = "^3.1.13" }
django-oidc-provider = "^0.8.0"
openai = "^1.35.3"
openai = "^1.35.14"
django-silk = "^5.0.3"
redis = { extras = ["hiredis"], version = "^5.0.3" }
ronkyuu = "^0.9"
Expand Down
3 changes: 2 additions & 1 deletion search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def search_for_players_played_with(request, npln_id: str):
return HttpResponseBadRequest('You cannot search for yourself.')

players = Player.objects.filter(team__battle__uploader_id=request.user.id, npln_id__iexact=npln_id).distinct()
battles_with_player = Battle.objects.filter(teams__players__in=players).distinct().order_by('-played_time')
battles_with_player = Battle.objects.with_prefetch().filter(teams__players__in=players).distinct().order_by(
'-played_time')

return render(request, 'search/search_for_players_played_with.html', {
'battles': battles_with_player,
Expand Down
2 changes: 1 addition & 1 deletion users/templates/users/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% block opengraph_head %}
<meta property="og:title" content="{{ profile_user.display_name }} (@{{ profile_user.username }})">

<meta property="og:description" content="Splashcat records battle data for later analysis.">
<meta property="og:description" content="Splashcat is an award-winning service that records battle data for later analysis.">

<meta name="twitter:card" content="summary_large_image">
<meta property="og:image"
Expand Down
2 changes: 1 addition & 1 deletion users/templates/users/profile_album.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% block opengraph_head %}
<meta property="og:title" content="{{ profile_user.display_name }}'s Album'">

<meta property="og:description" content="Splashcat records battle data for later analysis.">
<meta property="og:description" content="Splashcat is an award-winning service that records battle data for later analysis.">

<meta name="twitter:card" content="summary_large_image">
<meta property="og:image"
Expand Down

0 comments on commit e7cee67

Please sign in to comment.