llm4pcg


Namellm4pcg JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryLLM4PCG is a python package containing required and utility functions of ChatGPT4PCG competition, but modified to support local LLMs that compatible with OpenAI API interface.
upload_time2024-03-21 03:31:14
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseMIT License Copyright (c) 2024 Pittawat Taveekitworachai Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords chatgpt chatgpt4pcg competition
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LLM4PCG

LLM4PCG is a python package containing required and utility functions of ChatGPT4PCG competition, but modified to
support local LLMs that compatible with OpenAI API interface.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install LLM4PCG.

```bash
pip install llm4pcg
```

## Dependency

This file uses the following Python libraries:

- `openai`

## Functions

### `run_evaluation(team_name: str, fn: Type[TrialLoop], num_trials=10, characters: list[str] = None, model_name=None, local_model_base_url=None)`

This function runs a trial for each character in the alphabet for a given team. It creates directories for logging and
output, and generates a log file with a timestamp and timezone in the filename. It then runs trials for each character,
skipping any that already exist.

To use local LLM, specify `model_name` and `local_model_base_url` parameters. If `model_name` is not specified, it will
use the default model name `gpt-3.5-turbo`. If `local_model_base_url` is not specified, it will use the default base
url of OpenAI API.

### `run_trial(ctx: TrialContext, fn: Type[TrialLoop])`

This function runs a single trial. It writes the result of the trial to the log file and the final response to a text
file in the output directory.

### `chat_with_llm(ctx: TrialContext, messages: []) -> list[str]`

This function chats with the LLM. It sends a list of messages to the LLM and writes the response and token
counts to the log file. It also checks for time and token limits, raising errors if these are exceeded.

## Usage

To use this file, import it and call the `run_evaluation` function with the team name and trial loop function as
arguments. You can also specify the number of trials to run and the characters to run trials for.

```python
from llm4pcg.competition import run_evaluation, TrialLoop, TrialContext, chat_with_llm


class ZeroShotPrompting(TrialLoop):
    @staticmethod
    def run(ctx: TrialContext, target_character: str) -> str:
        message_history = [{
            "role": "user",
            "content": "Return this is a test message."
        }]

        response = chat_with_llm(ctx, message_history)
        return response[0]


run_evaluation("y_wing", ZeroShotPrompting)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "llm4pcg",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "Pittawat Taveekitworachai <pittawat.pete@gmail.com>",
    "keywords": "chatgpt, chatgpt4pcg, competition",
    "author": null,
    "author_email": "ChatGPT4PCG Organizing Team <chatgpt4pcg@gmail.com>, Pittawat Taveekitworachai <pittawat.pete@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/31/48/08a88b6afb082baed499dd9cf113e09c37bd785b2b4154531dc83e946223/llm4pcg-1.0.1.tar.gz",
    "platform": null,
    "description": "# LLM4PCG\n\nLLM4PCG is a python package containing required and utility functions of ChatGPT4PCG competition, but modified to\nsupport local LLMs that compatible with OpenAI API interface.\n\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install LLM4PCG.\n\n```bash\npip install llm4pcg\n```\n\n## Dependency\n\nThis file uses the following Python libraries:\n\n- `openai`\n\n## Functions\n\n### `run_evaluation(team_name: str, fn: Type[TrialLoop], num_trials=10, characters: list[str] = None, model_name=None, local_model_base_url=None)`\n\nThis function runs a trial for each character in the alphabet for a given team. It creates directories for logging and\noutput, and generates a log file with a timestamp and timezone in the filename. It then runs trials for each character,\nskipping any that already exist.\n\nTo use local LLM, specify `model_name` and `local_model_base_url` parameters. If `model_name` is not specified, it will\nuse the default model name `gpt-3.5-turbo`. If `local_model_base_url` is not specified, it will use the default base\nurl of OpenAI API.\n\n### `run_trial(ctx: TrialContext, fn: Type[TrialLoop])`\n\nThis function runs a single trial. It writes the result of the trial to the log file and the final response to a text\nfile in the output directory.\n\n### `chat_with_llm(ctx: TrialContext, messages: []) -> list[str]`\n\nThis function chats with the LLM. It sends a list of messages to the LLM and writes the response and token\ncounts to the log file. It also checks for time and token limits, raising errors if these are exceeded.\n\n## Usage\n\nTo use this file, import it and call the `run_evaluation` function with the team name and trial loop function as\narguments. You can also specify the number of trials to run and the characters to run trials for.\n\n```python\nfrom llm4pcg.competition import run_evaluation, TrialLoop, TrialContext, chat_with_llm\n\n\nclass ZeroShotPrompting(TrialLoop):\n    @staticmethod\n    def run(ctx: TrialContext, target_character: str) -> str:\n        message_history = [{\n            \"role\": \"user\",\n            \"content\": \"Return this is a test message.\"\n        }]\n\n        response = chat_with_llm(ctx, message_history)\n        return response[0]\n\n\nrun_evaluation(\"y_wing\", ZeroShotPrompting)\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Pittawat Taveekitworachai  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "LLM4PCG is a python package containing required and utility functions of ChatGPT4PCG competition, but modified to support local LLMs that compatible with OpenAI API interface.",
    "version": "1.0.1",
    "project_urls": {
        "Bug Reports": "https://github.com/Pittawat2542/llm4pcg-python/issues",
        "Homepage": "https://chatgpt4pcg.github.io/",
        "Source": "https://github.com/Pittawat2542/llm4pcg-python"
    },
    "split_keywords": [
        "chatgpt",
        " chatgpt4pcg",
        " competition"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0dbe9956da285c41e63ed0cbb1290a9cc96df50db4f79b61e5757937ed002c2b",
                "md5": "7142e48bab0ca319fe7b15a5ee852801",
                "sha256": "a928fcff78e2fdea487d5a7e0368791b9c651cc1f2870c42451bcdf39e18e544"
            },
            "downloads": -1,
            "filename": "llm4pcg-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7142e48bab0ca319fe7b15a5ee852801",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 7330,
            "upload_time": "2024-03-21T03:31:12",
            "upload_time_iso_8601": "2024-03-21T03:31:12.834065Z",
            "url": "https://files.pythonhosted.org/packages/0d/be/9956da285c41e63ed0cbb1290a9cc96df50db4f79b61e5757937ed002c2b/llm4pcg-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "314808a88b6afb082baed499dd9cf113e09c37bd785b2b4154531dc83e946223",
                "md5": "3df864d959822ba3d5c8b0590a537f86",
                "sha256": "403f783701dade508d1b2ee59893413c50923de4246cff615cac7602c70b0242"
            },
            "downloads": -1,
            "filename": "llm4pcg-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3df864d959822ba3d5c8b0590a537f86",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 7237,
            "upload_time": "2024-03-21T03:31:14",
            "upload_time_iso_8601": "2024-03-21T03:31:14.653466Z",
            "url": "https://files.pythonhosted.org/packages/31/48/08a88b6afb082baed499dd9cf113e09c37bd785b2b4154531dc83e946223/llm4pcg-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-21 03:31:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Pittawat2542",
    "github_project": "llm4pcg-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "llm4pcg"
}
        
Elapsed time: 0.21611s