Skip to content

Forum in maintenance, we will back soon 🙂

Hosting fast API on...
 
Notifications
Clear all

Hosting fast API on VPS server

39 Posts
4 Users
6 Reactions
434 Views
Hasan Aboul Hasan
(@admin)
Posts: 1252
Member Admin
 

This means that the URL is wrong.

there is a dropdown on top, you need to select your URL. 

if it is not there, you need to add it first in the API template in the main.py

 
Posted : 05/26/2024 8:13 am
Dim2001
(@dassa)
Posts: 99
Member
Topic starter
 

Thank you Mr.Hasan. working.

 
Posted : 05/27/2024 4:10 am
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

@dassa look at the info from this search: https://learnwithhasan.com/premium-forum/?wpfs=cors

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 05/27/2024 7:54 pm
Dim2001
(@dassa)
Posts: 99
Member
Topic starter
 

Everything working perfectly. 

Screenshot 2

but points were not deducted. and also the tool works without points too. cannot figure out why.

 

 
Posted : 06/03/2024 6:24 am
(@husein)
Posts: 529
Member Moderator
 

@dassa Attach your php code snippet please so we can take a look at it, maybe you didn't add the function that detects points. 

And are you sure you setup the mycred system and points correctly?

 
Posted : 06/03/2024 12:48 pm
Dim2001
(@dassa)
Posts: 99
Member
Topic starter
 

@husein

those are the 2 tools i have created.

// Bulk Domain Name Generator
$domainnamegenaratorToolConfig = [
    'ENABLE_LOGGING' => false,
    'CUSTOM_TOOL_ID' => 1,
    'AUTH_REQUIRED' => false,
    'POINTS_REQUIRED' => 8,
    'ENDPOINT_PATH' => '/domain_name_generator',
    'TOOL_NAME' => "Bulk Domain Name Generator",
    'EXPECTED_PARAMS' => [
        'niche' => [
            'type' => 'string',
            'error_message' => 'Niche not provided.'
        ]
    ]
];

custom_lws_tool_setup('bulk_Domain_name_generator', $domainnamegenaratorToolConfig);


// Hook Generator
$HookgenaratorToolConfig = [
    'ENABLE_LOGGING' => false,
    'CUSTOM_TOOL_ID' => 2,
    'AUTH_REQUIRED' => false,
    'POINTS_REQUIRED' => 5,
    'ENDPOINT_PATH' => '/hooks/generate',
    'TOOL_NAME' => "Hook Generator",
    'EXPECTED_PARAMS' => [
        'topic' => [
            'type' => 'string',
            'error_message' => 'topic not provided.'
        ],
        'usage' => [
            'type' => 'string',
            'regex' => '/^[A-Z]{2}$/',
            'default' => 'DEFAULT',
            'error_message' => 'usage not provided.'
        ]
    ]
];

custom_lws_tool_setup('hook_generator', $HookgenaratorToolConfig);
 
Posted : 06/04/2024 5:54 am
Hasan Aboul Hasan
(@admin)
Posts: 1252
Member Admin
 

you should set 'AUTH_REQUIRED' => true,

 
Posted : 06/04/2024 10:38 am
Dim2001
(@dassa)
Posts: 99
Member
Topic starter
 

Hi, I have already created more than 8 tools. but recently I developed YouTube tools that generate YouTube to bullet points and also YouTube to tweeter threads. that code works fine locally. but after I pushed into digital ocean it gave me an error.

tool code:

# Standard library imports
import json
import logging
import time

# Third-party imports
from fastapi import APIRouter,Request
from pydantic import ValidationError
from typing import List

from pydantic import BaseModel
from ..models.blog_models import youtubeTitles, youtubeSummary, youtubeTweet, youtubeBlog
#from SimplerLLM.language.llm import LLM, LLMProvider
from SimplerLLM.tools.generic_loader import load_content

# Local imports
from ..services import llm_api as llm, prompts as pr

logger = logging.getLogger("AppLogger")
router = APIRouter()
#llm_instance = LLM.create(provider=LLMProvider.OPENAI, model_name="gpt-4o")




@router.get("/youtube/generate-buletpoint")
async def generate_youtube_bulletpoints(youtube_url: str, request: Request):
    start_time = time.time()
    max_retries = 5

    for retry_count in range(max_retries):
        try:
            # Retrieve YouTube transcript content
            content = load_content(youtube_url).content

            #if await llm_instance.is_text_flagged(content):
                #return {
                    #"success": False,
                    #"message": "Content Not Allowed",
                   # "result": None
               # }

            prompt = pr.youtube_bulletpoint.format(input=content)
            result : youtubeSummary = await llm.generate_with_response_model(prompt,1,youtubeSummary)
          
      
            success_result = True
            return {
                "success": True,
                "message": "Generated Summery Successfully",
                "result": result.titles
            }

        except (json.JSONDecodeError, ValidationError) as e:
            logger.warning(
                f"Failed during JSON decoding or validation. Retry count: {retry_count + 1}."
            )
            
        except KeyError as e:
            logger.warning(f"Missing key in JSON: {e}")
            
        except Exception as e:
            logger.error(e)
            continue
        finally:
            elapsed_time = time.time() - start_time
            #do soemthing with the elapsed time

    return {
        "success": False,
        "message": f"Failed to generate Summery",
        "result": None
    }


@router.get("/youtube/generate-tweets")
async def generate_tweets(youtube_url: str, request: Request):
    start_time = time.time()
    max_retries = 5

    for retry_count in range(max_retries):
        try:
            # Retrieve YouTube transcript content
            content = load_content(youtube_url).content

            prompt = pr.youtube_to_tweet.format(input=content)
            result: youtubeTweet = await llm.generate_with_response_model(prompt, 1, youtubeTweet)

            success_result = True
            return {
                "success": True,
                "message": "Generated Tweets Successfully",
                "result": result.Tweets
            }

        except (json.JSONDecodeError, ValidationError) as e:
            logger.warning(
                f"Failed during JSON decoding or validation. Retry count: {retry_count + 1}. Error: {e}"
            )

        except KeyError as e:
            logger.warning(f"Missing key in JSON: {e}")

        except Exception as e:
            logger.error(f"An error occurred: {e}")
            continue
        finally:
            elapsed_time = time.time() - start_time
            logger.info(f"Elapsed time: {elapsed_time}s")

    return {
        "success": False,
        "message": "Failed to generate Tweets",
        "result": None
    }

 

 

this is what digital ocean support told me:

Upon reviewing the "monkfish-app" app, I could see the below errors in the runtime logs :

python-fast-api-main 2024-07-24T04:58:27.679611277Z INFO:     112.135.204.83:0 - "GET /customdocs HTTP/1.1" 200 OK
python-fast-api-main 2024-07-24T04:58:28.729663721Z INFO:     112.135.204.83:0 - "GET /openapi.json HTTP/1.1" 200 OK
python-fast-api-main 2024-07-24T05:00:10.885165969Z INFO:     112.135.204.83:0 - "GET /youtube/generate-tweets?youtube_url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSfBPqdH7wyo HTTP/1.1" 200 OK
python-fast-api-main 2024-07-24T05:06:00.108084949Z INFO:     112.135.204.83:0 - "GET / HTTP/1.1" 404 Not Found
python-fast-api-main 2024-07-24T05:06:00.647547356Z INFO:     112.135.204.83:0 - "GET /favicon.ico HTTP/1.1" 401 Unauthorized
python-fast-api-main 2024-07-24T05:10:48.710596621Z INFO:     112.135.204.83:0 - "GET /youtube/generate-tweets?youtube_url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSfBPqdH7wyo HTTP/1.1" 200 OK
python-fast-api-main 2024-07-24T05:12:33.997244131Z INFO:     112.135.204.83:0 - "GET /youtube/generate-buletpoint?youtube_url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSfBPqdH7wyo HTTP/1.1" 200 OK
python-fast-api-main 2024-07-24T05:44:00.733051527Z INFO:     2405:201:d019:24:45fe:7eb9:1cb9:64e2:0 - "GET / HTTP/1.1" 404 Not Found
python-fast-api-main 2024-07-24T05:44:01.865361171Z INFO:     2405:201:d019:24:45fe:7eb9:1cb9:64e2:0 - "GET /favicon.ico HTTP/1.1" 401 Unauthorized
python-fast-api-main 2024-07-24T06:39:01.159643115Z INFO:     185.188.61.216:0 - "GET / HTTP/1.1" 404 Not Found
python-fast-api-main 2024-07-24T06:39:01.559017858Z INFO:     185.188.61.216:0 - "GET /favicon.ico HTTP/1.1" 401 Unauthorized
python-fast-api-main 2024-07-24T07:54:11.376188373Z INFO:     152.42.174.176:0 - "GET /wp-admin/setup-config.php?step=1 HTTP/1.1" 401 Unauthorized
python-fast-api-main 2024-07-24T07:54:12.194482860Z INFO:     152.42.174.176:0 - "GET /wordpress/wp-admin/setup-config.php?step=1 HTTP/1.1" 401 Unauthorized
python-fast-api-main 2024-07-24T08:25:34.077917074Z INFO:     213.232.87.232:0 - "GET /.ssh/id_ed25519 HTTP/1.1" 401 Unauthorized

 

 
Posted : 07/27/2024 6:06 am
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

@dassa this log snippet tells you nothing about any errors. This snippet looks common to the process. Is there a specific error you're trying to overcome?

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 07/27/2024 2:18 pm
Dim2001 reacted
Hasan Aboul Hasan
(@admin)
Posts: 1252
Member Admin
 

return the exceptions and errors with the response, maybe we can spot what is going on. or share the logs

 
Posted : 07/28/2024 9:54 am
Dim2001 reacted
Dim2001
(@dassa)
Posts: 99
Member
Topic starter
 

@admin Thank you for your help. fast API output.

Response body

{
  "success": false,
  "message": "Failed to generate Tweets",
  "result": null
}


Response headers

 cache-control: private 
 cf-cache-status: MISS 
 cf-ray: 8aa536a2d8d95134-CMB 
 content-encoding: br 
 content-type: application/json 
 date: Sun,28 Jul 2024 13:28:41 GMT 
 last-modified: Sun,28 Jul 2024 13:28:41 GMT 
 server: cloudflare 
 vary: Accept-Encoding 
 x-do-app-origin: 0b51663a-d999-446b-98ae-bc669263fd6d 
 x-do-orig-status: 200 

 

Is this you are asking?

 

 

 
Posted : 07/28/2024 1:32 pm
Hasan Aboul Hasan
(@admin)
Posts: 1252
Member Admin
 

no I mean the exceptions in the code, return them in the "message"

 
Posted : 07/29/2024 3:30 pm
Dim2001
(@dassa)
Posts: 99
Member
Topic starter
 

Did not get you. please explain if you can. thanks

 
Posted : 07/29/2024 4:42 pm
(@husein)
Posts: 529
Member Moderator
 

@dassa Edit the code so that the error the code encounters is returned in the "message" section so that we can know what the error is and help you. So, instead of it returning this:

"message": "Failed to generate Tweets"

 

It returns the specific error its encountering.

 
Posted : 07/30/2024 8:23 am
Hasan Aboul Hasan
(@admin)
Posts: 1252
Member Admin
 

@dassa, in order to know what's happening on the server, we need to see the detailed errors and exceptions happening. Either you need to log on to the server and share the log with us or try to return the exception message with the message coming.

 
Posted : 07/30/2024 12:13 pm
Page 2 / 3
Share:
build ai agents ad