Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstring how to connect when handling connection error #143

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions factgenie/llm_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import ast
import logging
import traceback
import requests
import urllib3

from slugify import slugify

from factgenie.campaigns import CampaignMode, CampaignStatus, ExampleStatus
from flask import jsonify
import factgenie.utils as utils
Expand Down Expand Up @@ -183,6 +186,12 @@ def run_llm_campaign(app, mode, campaign_id, announcer, campaign, datasets, mode
res["output"] = generated_output["output"]
elif mode == CampaignMode.LLM_GEN:
res = model.generate_output(data=example)
except requests.exceptions.ConnectionError as e:
traceback.print_exc()
return utils.error(
f"Error processing example {dataset_id}-{split}-{example_idx}: {e.__class__.__name__}: {str(e)}\n\n{model.new_connection_error_advice_docstring}\n"
)

except Exception as e:
traceback.print_exc()
return utils.error(
Expand Down
22 changes: 18 additions & 4 deletions factgenie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import traceback
from openai import OpenAI
from textwrap import dedent
import argparse
import yaml
import json
import sys

from pathlib import Path
import os
Expand All @@ -20,7 +17,6 @@
from factgenie.campaigns import CampaignMode

# logging.basicConfig(format="%(message)s", level=logging.INFO, datefmt="%H:%M:%S")
# coloredlogs.install(level="INFO", fmt="%(asctime)s %(levelname)s %(message)s")
logger = logging.getLogger(__name__)

DIR_PATH = os.path.dirname(__file__)
Expand Down Expand Up @@ -66,6 +62,10 @@ def __init__(self, config):
# the key in the model output that contains the annotations
self.annotation_key = config["extra_args"].get("annotation_key", "annotations")

@property
def new_connection_error_advice_docstring(self):
return """Please check the LLM engine documentation. The call to the LLM API server failed."""

def get_annotator_id(self):
return "llm-" + self.config["type"] + "-" + self.config["model"]

Expand Down Expand Up @@ -233,6 +233,13 @@ def __init__(self, config):

self.set_api_endpoint()

@property
def new_connection_error_advice_docstring(self):
return """\
Please check the Ollama documentation:
https://github.com/ollama/ollama?tab=readme-ov-file#generate-a-response
"""

def set_api_endpoint(self):
# make sure the API URL ends with the `generate` endpoint
self.config["api_url"] = self.config["api_url"].rstrip("/")
Expand Down Expand Up @@ -457,6 +464,13 @@ def __init__(self, config):

self.set_api_endpoint()

@property
def new_connection_error_advice_docstring(self):
return """\
Please check the Ollama documentation:
https://github.com/ollama/ollama?tab=readme-ov-file#generate-a-response
"""

def set_api_endpoint(self):
# make sure the API URL ends with the `chat` endpoint
self.config["api_url"] = self.config["api_url"].rstrip("/")
Expand Down
Loading