Metadata-Version: 2.1
Name: llm4pcg
Version: 1.0.0.post1
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.
Author-email: ChatGPT4PCG Organizing Team <chatgpt4pcg@gmail.com>, Pittawat Taveekitworachai <pittawat.pete@gmail.com>
Maintainer-email: Pittawat Taveekitworachai <pittawat.pete@gmail.com>
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.
Project-URL: Homepage, https://chatgpt4pcg.github.io/
Project-URL: Bug Reports, https://github.com/Pittawat2542/llm4pcg-python/issues
Project-URL: Source, https://github.com/Pittawat2542/llm4pcg-python
Keywords: chatgpt,chatgpt4pcg,competition
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openai

# 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)
```
