Skip to main content

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.

Project description

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 to install LLM4PCG.

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.

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm4pcg-1.0.2.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

llm4pcg-1.0.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file llm4pcg-1.0.2.tar.gz.

File metadata

  • Download URL: llm4pcg-1.0.2.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for llm4pcg-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8a99e15c41977933a6ea3292b4814cdbcca5de652ca396afe640215a49691857
MD5 32c3c7e055f10b05652bc7ceb9e7196d
BLAKE2b-256 021421691836aef2d88b7b391fc9cdc2188f021d8f984c09ec0657b1eb2f5064

See more details on using hashes here.

File details

Details for the file llm4pcg-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: llm4pcg-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for llm4pcg-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 23b6a0c091ed8e7a13083821c573120d8fb5f2609575fbff6acfebaabc279cf3
MD5 78c86ad48b68bfc04fb769f265b3a8d1
BLAKE2b-256 9cd93ef550be57888d27cca142a2dc5174b101554ac5694e9f0c568e24c3ee67

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page