Skip to content

Commit

Permalink
Add docstring how to connect when handling connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
oplatek committed Nov 5, 2024
1 parent 73a7efe commit d0ad24f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
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

0 comments on commit d0ad24f

Please sign in to comment.