KAG icon indicating copy to clipboard operation
KAG copied to clipboard

Fail to create project with knext command

Open JerryWang20 opened this issue 4 months ago • 3 comments

Search before asking

  • [x] I had searched in the issues and found no similar issues.

Operating system information

Windows

What happened

On version 0.8, while running the command to create the project: knext project restore --host_addr http://172.179.138.222:8887 --proj_path . it fail with following error: (kagv2) C:\TestProj\Python\KAGv2\KAG\kag\examples\bas_da_kb>knext project restore --host_addr http://172.179.138.222:8887 --proj_path . Traceback (most recent call last): File "\AppData\Roaming\uv\python\cpython-3.10.16-windows-x86_64-none\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "\AppData\Roaming\uv\python\cpython-3.10.16-windows-x86_64-none\lib\runpy.py", line 86, in run_code exec(code, run_globals) File "C:\PythonEnv\kagv2\Scripts\knext.exe_main.py", line 10, in sys.exit(_main()) File "C:\PythonEnv\kagv2\lib\site-packages\click\core.py", line 1157, in call return self.main(*args, **kwargs) File "C:\PythonEnv\kagv2\lib\site-packages\click\core.py", line 1078, in main rv = self.invoke(ctx) File "C:\TestProj\Python\KAGv2\KAG\knext\command\exception.py", line 21, in invoke return super().invoke(ctx) File "C:\PythonEnv\kagv2\lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\PythonEnv\kagv2\lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\PythonEnv\kagv2\lib\site-packages\click\core.py", line 1434, in invoke return ctx.invoke(self.callback, **ctx.params) File "C:\PythonEnv\kagv2\lib\site-packages\click\core.py", line 783, in invoke return __callback(args, **kwargs) File "C:\TestProj\Python\KAGv2\KAG\knext\command\sub_command\project.py", line 235, in restore_project project = client.create( File "C:\TestProj\Python\KAGv2\KAG\knext\project\client.py", line 89, in create project = self._rest_client.project_create_post( File "C:\TestProj\Python\KAGv2\KAG\knext\project\rest\project_api.py", line 68, in project_create_post return self.project_create_post_with_http_info(**kwargs) # noqa: E501 File "C:\TestProj\Python\KAGv2\KAG\knext\project\rest\project_api.py", line 144, in project_create_post_with_http_info return self.api_client.call_api( File "C:\TestProj\Python\KAGv2\KAG\knext\common\rest\api_client.py", line 419, in call_api return self.__call_api( File "C:\TestProj\Python\KAGv2\KAG\knext\common\rest\api_client.py", line 219, in __call_api raise e File "C:\TestProj\Python\KAGv2\KAG\knext\common\rest\api_client.py", line 207, in __call_api response_data = self.request( File "C:\TestProj\Python\KAGv2\KAG\knext\common\rest\api_client.py", line 495, in request return self.rest_client.POST( File "C:\TestProj\Python\KAGv2\KAG\knext\common\rest\rest.py", line 345, in POST return self.request( File "C:\TestProj\Python\KAGv2\KAG\knext\common\rest\rest.py", line 257, in request raise ApiException(http_resp=r) knext.common.rest.exceptions.ApiException: (400) Reason: HTTP response headers: HTTPHeaderDict({'Access-Control-Allow-Origin': '', 'Access-Control-Allow-Methods': 'POST, PUT, GET, DELETE', 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, client_id, uuid, Authorization, credentials', 'Access-Control-Allow-Credentials': 'true', 'Access-Control-Max-Age': '3600', 'Vary': 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers', 'TraceId': '0af000e6175448712032810981', 'Remote': '10.240.0.230', 'Content-Type': 'application/json;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Date': 'Wed, 06 Aug 2025 13:32:00 GMT', 'Connection': 'close'}) HTTP response body: "PemjaUtils.invoke Exception:pemja.core.PythonException: \u003cclass \u0027RuntimeError\u0027\u003e: invalid vectorizer config: call AzureOpenAIVectorizeModel.init failed, details:AzureOpenAI.init() got an unexpected keyword argument \u0027model\u0027"

How to reproduce

Here is the verctor config

vectorize_model: &vectorize_model api_key: **** base_url: https://dowopenaipoceu.openai.azure.com/ model: text-embedding-3-small azure_deployment: text-embedding-3-small api_version: 2024-12-01-preview type: azure_openai vector_dimensions: 1536 enable_check: false vectorizer: *vectorize_model

Are you willing to submit PR?

  • [ ] Yes I am willing to submit a PR!

JerryWang20 avatar Aug 06 '25 13:08 JerryWang20

I met the same problem. Is there any solution?

hollandloprabbit avatar Aug 07 '25 07:08 hollandloprabbit

I can confirm I'm experiencing this problem as well. Are there any updates on a potential fix? ubuntu 24

EAkhalid avatar Aug 07 '25 09:08 EAkhalid

Hello everyone,

I encountered the same HTTP 400 Bad Request error when trying to create a project. The server logs showed a JsonSyntaxException with the message Expected a string but was BEGIN_OBJECT.

I was able to solve this issue. The problem is that the server expects parameters like config, auto_schema, and tag to be sent as a JSON string, not as a raw JSON object.

The Fix:

You need to modify the client-side code to convert these Python dictionaries into JSON strings before sending the API request. Based on my working solution, here is the corrected create function, likely in your client.py file:


``` import json
# Make sure 'rest' is imported, for example:
# from knext_site.rest_client.client import models as rest

# ...

def create(self, name: str, namespace: str, config: str, **kwargs):
    if not self._rest_client:
        raise Exception("Please set KAG_PROJECT_HOST_ADDR and KAG_PROJECT_ID")
    
    visibility = kwargs.get("visibility", "PRIVATE")
    tag_value = kwargs.get("tag", "LOCAL") # Renamed to avoid conflict
    auto_schema_value = kwargs.get("auto_schema", False) # Renamed to avoid conflict
    desc = kwargs.get("desc", None)
    userNo = kwargs.get("userNo", "openspg")

    # The core of the fix: Convert dictionaries/values to JSON strings
    config_as_string = json.dumps(config)
    auto_schema_as_string = json.dumps(auto_schema_value)
    tag_as_string = json.dumps(tag_value)

    # Create the request object using the stringified values
    project_create_request = rest.ProjectCreateRequest(
        name=name,
        desc=desc,
        namespace=namespace,
        config=config_as_string,         # Use the string version here
        auto_schema=auto_schema_as_string, # and here
        visibility=visibility,
        tag=tag_as_string,                 # and here
        userNo=userNo,
    )

    project = self._rest_client.project_create_post(
        project_create_request=project_create_request
    )
    return project

EAkhalid avatar Aug 07 '25 09:08 EAkhalid