Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Antelofski committed Dec 7, 2024
1 parent 6260b6f commit 329c3f3
Show file tree
Hide file tree
Showing 34 changed files with 13,104 additions and 1 deletion.
3 changes: 3 additions & 0 deletions system/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
172 changes: 172 additions & 0 deletions system/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Others
.DS_Store
.next/
.vscode/
.ignore.env
openaitest.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Node modules
node_modules/

# MACOSX
__MACOSX/
16 changes: 15 additions & 1 deletion system/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@

ROPE training system code to be updated
ROPE training system code to be updated

cd .\system\
npm install
npm run dev

using a browser to access http://localhost:3333

change game:

There are three buttons in the bottom left corner of the page, the third button is' Change Game'
open it , you can see a select box and 'add game' and 'delete game'.
if you wang to add game,you shoule upload two files:'game file' and 'game code'.
You can find file examples in /system/lib/connect4/code.txt and /system/lib/connect4/data.json.
code.txt is game code, data.json is game file.
113 changes: 113 additions & 0 deletions system/app/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"use server";

// import * as dotenv from "dotenv";
// dotenv.config(); // { path: '/.env' });

import { createStreamableValue } from "ai/rsc";
import { prompts } from "../lib/prompts";
import OpenAI from "openai";
import { outputJsonMapper, PromptType } from "@/lib/interfaces";

const openaiBaseURL = "https://api.openai-proxy.com/v1";
const openaiApiKey = process.env.OPENAI_API_KEY;
const openaiModel35 = "gpt-3.5-turbo";
const openaiModel40 = "gpt-4o-2024-08-06";

const config = {
default: {
baseURL: openaiBaseURL,
apiKey: openaiApiKey,
model: openaiModel40,
max_tokens: 4096,
temperature: 0.7,
response_format: { type: "json_object" },
},
code: {
baseURL: openaiBaseURL,
apiKey: openaiApiKey,
model: openaiModel40,
max_tokens: 4096,
temperature: 0.3,
},
};

const converNL2json = (nl: string, promptType: PromptType) => {
if (promptType === "code") {
return {
prompt: nl,
examples: [
{
prompt: "Convert the following natural language to JSON:",
completion: nl,
},
],
};
}
};

export async function generate(
promptType: PromptType,
promptProps: any,
messages = []
) {
"use server";

let { baseURL, apiKey, model, max_tokens, temperature, response_format } =
config[promptType] || config.default;
if (promptType !== "code") {
response_format = outputJsonMapper[promptType];
}
const openai = new OpenAI({
apiKey,
baseURL,
});

const stream = createStreamableValue("");

(async () => {
try {
const systemPrompt = prompts[promptType](promptProps);
// console.log('openai api key', apiKey, model, max_tokens, temperature);
const theMessages = [
{ role: "system", content: systemPrompt },
...messages,
];
console.log("theMessages", theMessages);
const textStream = await openai.chat.completions.create({
model,
max_tokens,
temperature,
stream: true,
messages: theMessages as any,
response_format,
});
/*
const condidate = completion.choices[0].message;
console.log(condidate);
// If the model refuses to respond, you will get a refusal message
if (condidate.refusal) {
console.log(condidate.refusal);
stream.update(`ERROR: ${condidate.refusal}`);
} else {
text = condidate.parsed;
stream.update(`${condidate.parsed}`);
}
*/

for await (const chunk of textStream) {
const text =
chunk.choices?.[0]?.delta?.content ||
chunk.data?.choices?.[0]?.delta?.content;

stream.update(text);
}
stream.done();
} catch (error) {
console.log("ERROR OPENAI APIIIIII", apiKey);
console.log("ERROR", error);
//stream.update(`Error: ${error.message}`);
//stream.done();
}
})();
return { output: stream.value };
}
39 changes: 39 additions & 0 deletions system/app/api/conversation/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import clientPromise from "@/lib/mongodb";

export async function POST(request) {
const { username, chatType, timestamp, message, conversationId, gameName } =
await request.json();
// chatType user / gpt
const client = await clientPromise;

const db = client.db("multipleGame");
const collection = db.collection("conversation");
const conversation = await collection.findOne({ conversationId });
let result;
if (conversation) {
result = { insertedId: conversation._id };
let messages = [
...conversation.messages,
{ chatType, createTime: timestamp, message },
];
await collection.updateOne({ conversationId }, { $set: { messages } });
} else {
result = await collection.insertOne({
username,
createTime: timestamp,
messages: [{ chatType, createTime: timestamp, message }],
conversationId,
gameName,
});
}

return new Response(
JSON.stringify({ success: true, id: result.insertedId }),
{
status: 200,
headers: {
"Content-Type": "application/json",
},
}
);
}
Loading

0 comments on commit 329c3f3

Please sign in to comment.