# Tutorial

Stop spending time on prompt iteration! Follow a few steps to efficiently uncover your optimized system prompt.

{% hint style="info" %}
Want to integrate even quicker? Try out Farsight AI on a Colab notebook [here](https://colab.research.google.com/drive/1GvsRYFmKZZDc9U8ZyqbCD1dKPazt6uQw?usp=sharing).
{% endhint %}

*<mark style="color:red;">Note:</mark> While you have the flexibility to assess the results of any Language Model (LLM), we specifically leverage OpenAI for the evaluation functions in Farsight AI. To utilize our package, you must have access to an* [*OpenAI API Key*](https://platform.openai.com/account/api-keys)*.*&#x20;

### Setup A Python Environment[​](https://docs.confident-ai.com/docs/getting-started#setup-a-python-environement) <a href="#setup-a-python-environement" id="setup-a-python-environement"></a>

Go to the root directory of your project and create a virtual environment (if you don't already have one). In the CLI, run:

```python
python3 -m venv env
source venv/bin/activate
```

### Installation[​](https://docs.confident-ai.com/docs/getting-started#installation) <a href="#installation" id="installation"></a>

Install our library by running:&#x20;

```
pip install farsightai
```

### Suggested Starter Workflow

We suggest you start by generating a few system prompts via our generate prompts function, then start evaluating outputs using standard Farsight metrics. Follow the steps below:

1. [**Generate several system**](/sdk/step-by-step-prompt-optimization/prompt-generation.md) prompts using our prompt generation functionality (we recommend starting with 5).
2. Generate outputs using your preferred language model (e.g., Mistral, ChatGPT, Llama).
3. [**Evaluate the results**](/sdk/step-by-step-prompt-optimization/prompt-evaluation.md) using our prompt evaluation function or any of our additional metrics.

**We've provided an example of this suggested generation and evaluation process below.**

```python
from farsightai import FarsightAI
from openai import OpenAI

# Replace this with your openAI credentials
OPEN_AI_KEY = "<openai_key>"

# specify your use case parameters
num_prompts = 5
task = 'You are a chatbot answering scientific questions'
context = 'You have knowledge on all scientific concepts'
guidelines = ["Use limited jargon."]

# generate a few system prompts to evaluate
generated_prompts = farsight.generate_prompts(num_prompts, task, context, guidelines)
print("generated_prompts: ", generated_prompts)

# generate the outputs to evaluate
client = OpenAI(api_key=OPEN_AI_KEY)
input = "Can you describe the carbon cycle"
outputs = []
for system_prompt in generated_prompts:
    chatCompletion = client.chat.completions.create(
        model="gpt-3.5-turbo",
         messages = [
            {"role": "system", "content": system_prompt},
            {"role": "user", "content": input},
        ],
    )
    output = chatCompletion.choices[0].message.content
    knowledge = None

# find your best prompt
criteria_description = """Can the model's response be understood by a non-expert
in the subject"""

rubric = """
Score 1: The response is filled with jargon and complex language, making it incomprehensible for a non-expert.
Score 2: the response includes some explanations, but still relies heavily on jargon and complex language.
Score 3: The response is somewhat clear, but could still be challenging for a non-expert to fully understand.
Score 4: the response is mostly comprehensible to a non-expert, with only a few complex terms or concepts
Score 5: the response is completely clear and understandable for a non-expert, with no reliance on jargon or complex language.
"""

reference_answer = """Photosynthesis is the process by which plants make their own
food using sunlight. In simple terms, they take in carbon dioxide from the air and
water from the soil, and with the help of sunlight, they transform these into sugars,
which the plant uses as energy. In the process, oxygen is released into the air,
benefiting the environment. So, photosynthesis is like the plant's way of cooking up
its own food using sunlight and a few basic ingredients."""


# Call the best_prompt function
best_prompt = farsight.best_prompt(
    criteria_description, rubric, reference_answer, system_propmts, input, outputs
)
print(best_prompt)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api.farsight-ai.com/sdk/step-by-step-prompt-optimization/introduction/tutorial.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
