Skip to content

Commit

Permalink
Feat/improve messages context (#1)
Browse files Browse the repository at this point in the history
* refactor: remove some files

* chore: update package json
  • Loading branch information
eulixir authored Apr 20, 2024
1 parent 6d12466 commit 63370be
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 55 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## 1.1.0

### Added

- some adjustments to the contract with the client (#001)

## 1.0.0

- Released!!
25 changes: 0 additions & 25 deletions api/domain/services/callOpenAiService.ts

This file was deleted.

15 changes: 0 additions & 15 deletions api/domain/services/createNewMessageService.ts

This file was deleted.

30 changes: 27 additions & 3 deletions api/domain/services/guessAnimeService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
import OpenAI from 'openai'

import { Message } from '../../@types/message.js'
import { callOpenAiService } from './callOpenAiService.js'

export async function guessAnimeService(messages: Message[]) {
return await callOpenAiService(messages)
const apiKey = process.env.OPEN_AI_KEY

const openai = new OpenAI({
apiKey,
})

export async function guessAnimeService(incomingMessages: Message[]) {
const defaultMessage: Message = {
role: 'assistant',
content: 'Your objective is guess an anime name based on description',
}

const messages = [defaultMessage, ...incomingMessages]

const { choices } = await openai.chat.completions.create({
messages,
model: 'gpt-4-turbo',
})

const response: Message = {
role: 'assistant',
content: choices[0].message.content,
}

return [...messages, response]
}
4 changes: 1 addition & 3 deletions api/web/guessController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export async function guessController(req: VercelRequest, res: VercelResponse) {
return
}

res.setHeader('Content-Type', 'application/json')

res.status(200).json({
message: response,
messages: response,
})
}
10 changes: 1 addition & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
{
"name": "animator",
"version": "1.0.0",
"version": "1.1.0",
"description": "A way to find an anime that you forget the name",
"main": "api/main.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"start": "node dist/api/main.ts",
"dev": "tsc --watch & node dist/api/main.ts"
},
"author": "status-451",
"license": "MIT",
"type": "module",
"devDependencies": {
Expand Down

0 comments on commit 63370be

Please sign in to comment.