Issue with OpenAI API key while using it in Windows - windows

I have to fine-tune the OpenAI model on my custom dataset. I have created the dataset in jsonl format. I use the following commands on windows command line:
set OPENAI_API_KEY=<API key>
openai tools fine_tunes.prepare_data -f "train_data.jsonl"
The above commands run successfully and give me some suggestions for updating jsonl file. After this, I run the following command to fine-tune the 'curie' model.
openai api fine_tunes.create 'openai.api_key = <API key>' -t "train_data.jsonl" -m "curie"
But I am getting following issue:
←[91mError:←[0m Incorrect API key provided: "sk-iQJX*****************************************mux". You can find your API key at https://beta.openai.com. (HTTP status code: 401)
Can anybody help me out with this issue.

This is a common issue with an earlier version of the openai's CLI. If you haven't already, make sure you upgrade to the most recent version by doing
pip install --upgrade openai
One possible workaround is to just use a python script to do what you would normally do in the CLI.
# To train a model:
import os
import openai
os.environ["OPENAI_API_KEY"] = "sk-iQJX*****************************************mux"
os.system("openai api fine_tunes.create -t train_data.jsonl -m curie")

When assigning the API key in command line, dont use double quotes like:
API_KEY=ab-123123123123123231
This will solve the issue

Related

No environment configuration found. DefaultAzureCredential()

I am trying to use this python sample to authenticate a client with an Azure Service
# pip install azure-identity
from azure.identity import DefaultAzureCredential
# pip install azure-mgmt-compute
from azure.mgmt.compute import ComputeManagementClient
# pip install azure-mgmt-network
from azure.mgmt.network import NetworkManagementClient
# pip install azure-mgmt-resource
from azure.mgmt.resource import ResourceManagementClient
SUBSCRIPTION_ID = creds_obj['SUBSCRIPTION_ID']
# Create client
# For other authentication approaches, please see: https://pypi.org/project/azure-identity/
resource_client = ResourceManagementClient(
credential=DefaultAzureCredential(),
subscription_id=SUBSCRIPTION_ID
)
network_client = NetworkManagementClient(
credential=DefaultAzureCredential(),
subscription_id=SUBSCRIPTION_ID
)
compute_client = ComputeManagementClient(
credential=DefaultAzureCredential(),
subscription_id=SUBSCRIPTION_ID
)
I keep getting No environment configuration found.
The code sample is directly from the microsoft github: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/resources/azure-mgmt-resource/azure/mgmt/resource/resources/_resource_management_client.py. Ideally I would like to manage this configuration using environment variables or a config file. Is there any way to do this?
When using Azure Identity client library for Python, DefaultAzureCredential attempts to authenticate via the following mechanisms in this order, stopping when one succeeds:
You could set Environment Variables to fix it.
from azure.identity import DefaultAzureCredential
credential=DefaultAzureCredential()
Or set the properties in config and use ClientSecretCredential to create credential.
from azure.identity import ClientSecretCredential
subscription_id = creds_obj["AZURE_SUBSCRIPTION_ID"]
tenant_id = creds_obj["AZURE_TENANT_ID"]
client_id = creds_obj["AZURE_CLIENT_ID"]
client_secret = creds_obj["AZURE_CLIENT_SECRET"]
credential = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
I was having somewhat similar trouble following this Azure key vault tutorial which brought me here.
The solution I found was overriding the default values in the DefaultAzureCredential() constructor.
https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python
For reasons people far smarter than me will be able to explain I found that even though I had credentials from the azure cli it was not using those and instead looking for environment_credentials, which I did not have. So it threw an exception.
Once I set the exclude_environment_credential argument to True it then looked instead for the managed_identity_credentials, again which I did not have.
Eventually when I force excluded all credentials other than those from the cli it worked ok for me
I hope this helps someone. Those with more experience please feel free to edit as you see fit

How could I get schema.json of https://example.com/graphql using apollo-tooling

I am currently writing a third-party client for a website, but it doesn't expose interface, so I try to crawl datas by myself. The website uses GraphQL, so I use apollo-android in my project, By reading README.md of apollo-CLI, I still have trouble in generating schema.json file.
Could you tell me the detailed steps of how to generate schema.json?
For schema.json you should have apollo-codegen which is used to send an introspection query to server and get schema.json.
For getting apollo-codegen execute following from the command-prompt to install it:
npm install apollo-codegen -g
For sending the introspection query and getting the schema.json execute following:
apollo-codegen download-schema https://api.github.com/graphql --output schema.json
Replace https://api.github.com/graphql with your link
You can then find the schema.json file saved to the folder from where you ran the above commands.
Source
apollo-codegen had meanwhile be replaced with apollo:
The 'apollo-codegen' command has been replaced with the more-powerful 'apollo' CLI. Switch to 'apollo' to ensure future updates and visit https://npm.im/apollo#code-generation for more information.
So this would be:
sudo npm install apollo -g
And it's options:
$ apollo client:download-schema --help
Download a schema from Apollo or a GraphQL endpoint in JSON or SDL format
USAGE
$ apollo client:download-schema OUTPUT
ARGUMENTS
OUTPUT [default: schema.json] Path to write the introspection result to. Can be `.graphql`, `.gql`, `.graphqls`, or `.json`
OPTIONS
-c, --config=config Path to your Apollo config file
-g, --graph=graph The ID for the graph in Apollo to operate client commands with. Overrides config file if set.
-v, --variant=variant The variant of the graph in Apollo to associate this client to
--clientName=clientName Name of the client that the queries will be attached to
--clientReferenceId=clientReferenceId Reference id for the client which will match ids from client traces, will use clientName if not provided
--clientVersion=clientVersion The version of the client that the queries will be attached to
--endpoint=endpoint The URL for the CLI use to introspect your service
--excludes=excludes Glob of files to exclude for GraphQL operations. Caveat: this doesn't currently work in watch mode
--header=header Additional header to send during introspection. May be used multiple times to add multiple headers. NOTE: The `--endpoint` flag is REQUIRED if using the `--header` flag.
--includes=includes Glob of files to search for GraphQL operations. This should be used to find queries *and* any client schema extensions
--key=key The API key to use for authentication to Apollo
--queries=queries Deprecated in favor of the includes flag
--tagName=tagName Name of the template literal tag used to identify template literals containing GraphQL
queries in Javascript/Typescript code
For example:
apollo client:download-schema --endpoint=https://api.github.com/graphql schema.json

Yocto SYSTEMD_SERVICE to install a parameterized service ("#.service")

I need to configure WireGuard to bring up a VPN on boot on an Embedded Linux device.
My recipe installs a /etc/wireguard/wg0.conf pretty much like the examples found through the Internet.
Then I try to enable the service on SystemD like this on my wireguard.bb:
SYSTEMD_SERVICE = "wg-quick#wg0.service"
SYSTEMD_AUTO_ENABLE = "enable"
But bitbake throws me an error:
ERROR: Function failed: SYSTEMD_SERVICE_my-conf value wg-quick#wg0.service does not exist
I checked the temporary directory and file wg0.conf appears in the correct places but it seems that bitbake's SYSTEMD_SERVICE doesn't know how to expand the "wg0" after # sign.
If I try without the interface name (wg0):
SYSTEMD_SERVICE = "wg-quick#.service"
Bitbake is happy and finalizes my recipe, but it is not what systemd is expecting. Starting a service without an interface makes no sense...
Then I tried another approach and split the "wireguard" package itself from the configuration ("wireguard-conf" package) and added DEPENDS and RDEPENDS on "wireguard".
This got even worse since my wireguard-conf.bb recipe does not contain a "wg-quick#.service" file (it comes from the dependency "wireguard").
Well,
I don't know how to properly fix it and any suggestions will be highly appreciated.
Additional Info
I am using Yocto 2.0.3 in this project (with no hope of updating it).
Thanks to #TomasNovotny comments I managed to compare my "systemd.bbclas" against Github and noticed a change in systemd_populate_packages() that seems to solve the problem.
It works in newer OpenEmbedded (looks like in krogoth, version 2.1 released Apr 2016) and it is introduced by this commit. It works for me in rocko (version 2.4 released Oct 2017). According to j4x's comment, it doesn't work in jethro (version 2.0, Nov 2015).
For older (and currently unsupported OpenEmbeddeds) you can try to backport the patch or handle the symlinks for enabling the service in do_install().
Also please note that SYSTEMD_SERVICE_${PN} variable is package specific, so the _${PN} suffix has to be added (see manual).
I've also tried to enable OpenVPN with my profile (in Yocto rocko) without success.
Finally, I've made it working by providing OpenVPN recipe extension instead of custom one. So, the openvpn_%.bbappend file looks like:
inherit systemd
SYSTEMD_SERVICE_${PN} = "openvpn#clientprofile.service"
SYSTEMD_AUTO_ENABLE = "enable"
do_install_append() {
install -d ${D}${sysconfdir}/openvpn/
ln -sf /data/etc/openvpn/clientprofile.conf ${D}${sysconfdir}/openvpn/clientprofile.conf
}
As you can see, I'm using a symlink to my profile instead of the normal file. You can install a normal OpenVPN profile file instead of making symlink and it also works fine.

How to get project language from sonarqube API?

How can I get the main programming language of a project, using sonarqube API? Or a list of all of the project's programming languages?
Per SonarQube Metric Definitions documentation :
ncloc_language_distribution - Non Commenting Lines of Code Distributed By Language.
Use that with SonarQube WebAPI api/measures (documentation embedded in your SonarQube server) and you should be good to go.
Trying to solve the same problem, I came up with a small shell script that writes a list of all SonarQube project keys and the language distribution for the given project:
#!/bin/bash
API="http://my.sonar-server.com:9000/sonar/api" ### adjust this!
API_LANG_DIST="$API/measures/component?metricKeys=ncloc_language_distribution"
# get a list of all project keys:
projKeys=$(curl -s "$API/projects/index" | jq -r '.[].k')
# for each project key, get the language distribution metric:
for key in ${projKeys}; do
langDist=$(curl -s "${API_LANG_DIST}&componentKey=${key}" | jq '.component.measures[0].value')
printf "%-80s%-80s\n" ${key} ${langDist}
done
The output will be something like this:
com.mycompany:projectA "grvy=75;java=4091"
com.mycompany:projectB "css=1966;java=52770;js=11460;less=1862"
com.mycompany:projectC "css=40185;java=11451;js=13757"
Note: This script makes use of the jq JSON parsing utility. If you do not have it available, you can install it for example via sudo yum install jq.
(Tested on SonarQube 5.6.6 and 6.7.0)

Value error: embedded null byte when using pelican content command to generate my site on Windows

I want to use Pelican to generate my blog site. I install python 3 and Pelican by pip on Windows 7 with the guidance of docs quickstart. And I created a directory under D:/blog to store my site files. Then create a file named test.md under D:/blog/content and test.md's content is the same as the Quickstart guidance. When going to step Generate your site , I get an error
in gitbash as follows:
So, why it happened and how to fix it? Thanks.
Updated, use pelican content --debug command to get traceback, and the key traceback is here:
According to the bug report, this problem is due to the incorrect locale settings.
Execute the fllowing code,if a error occur,there exists a problem about locale settings.
import locale, time
locale.setlocale(locale.LC_ALL, 'ko')
time.strftime('%a')
Solution:
The error file is utils.pyunder the path..\Lib\site-packages\pelican\utils.py.Add the following code in strftime function to solve the problem.
locale.setlocale(locale.LC_ALL, 'en')
After adding (for example):
def strftime(date, date_format):
'''
Replacement for built-in strftime
...(Omit some words)
replacing formatted output back.
'''
locale.setlocale(locale.LC_ALL, 'en')
def strip_zeros(x):
return x.lstrip('0') or '0'
c89_directives = 'aAbBcdfHIjmMpSUwWxXyYzZ%'
you can also see the Chinese version in this blog post

Resources